question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@import Platform specific extensions

See original GitHub issue

hi , I Want import a scss file to my App.scss using @import with Platform specific extensions.

this is my code

@import "./assets/scss/main";

with this code I get error file not exist , but my file is main.android.scss exist.

please help me to use Platform specific extensions with @import

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
kristerkaricommented, Nov 15, 2018

Thanks for the response @mohammad76.

From your example it seems that you might be referencing the relative paths in a wrong way. You are thinking that the import always starts from the root folder.

So, if your App.scss is in the assets/scss folder, and inside it you are referencing to "./assets/scss/main", then it tries to find the file from assets/scss/assets/scss/main.android.scss.

If App.scss and main.android.scss are in the same folder then the import should be like this:

.head {
  color: #333;
  font-family: shabnam;
  text-align: center;
}

.viewbox{
  padding: 10px;
  border: 1px solid #ddd;
  margin: 10px;
  border-radius: 5px;
}

@import "./main";

or (I don’t remember if this also works):

.head {
  color: #333;
  font-family: shabnam;
  text-align: center;
}

.viewbox{
  padding: 10px;
  border: 1px solid #ddd;
  margin: 10px;
  border-radius: 5px;
}

@import "main";
1reaction
kristerkaricommented, Nov 14, 2018

@mohammad76 I just tested your example with one of the demo apps and it is working for me. Here’s what I did:

App.js

import test from "./test.scss";
<Text style={test.foo}>Test</Text>

test.scss

@import "./assets/scss/main";

assets/scss/main.android.scss

.foo {
  color: #f00;
}

When I run that on Android, the app renders a red text.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Platform Specific Code - React Native
Using platform-specific file extensions. Certain components may have properties that ... import {Platform, StyleSheet} from 'react-native';
Read more >
Platform specific import component in react native with typescript
Update: Another way of doing it is just omit the extension for one of them, then typescript will pick up the default one....
Read more >
Platform specific code - JavaScript Camp
Using file extensions for specific platforms. Some components may have properties that only work on ... import { Platform, StyleSheet } from 'react-native'...
Read more >
babel-plugin-react-native-platform-specific-extensions - GitHub
Allow react-native platform specific extensions to be used for other file types than Javascript. Example: import styles from "./styles.css";. styles.android.css ...
Read more >
React Native — Platform Specific Code | by Nedim Bećirović
All we need to do is import Platform from react-native and we're ... There is something called Platform-specific extension which I prefer.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found