Hey guys,
just playing with 1.3 + React - I’ve saved my components and stylesheets in imports/client/ui. Now my CSS files aren’t loaded into the application, because I didn’t import them. I know that the normal way is to save them all in client/stylesheets, but for a better structure, I want to have them in the folder of the specific component. Is there an easy way to import them via command within my component file?
For example something like:
import React from 'react';
import 'mycomp.css';
class MyComp extends React.Component {
/....
}
You should be able to do this with .css files. You just need to provide a correct relative path to the .css file. So for example: import '../imports/stylesheets/style.css'. When you do this Meteor will get your styles from that file and attach them to the <head>...</head>. This is how it works for now. Other option is to use some kind of preprocessor (the one you like the most) and create for example main.styl file outside the imports folder and in that file import all other .styl components which could be located in import folder in many places. Unfortunatelly Meteor don’t officially support such thing like CSS Modules right now.
Hey,
yeah, it works with that simple CSS code. I import it via import “./mycomp.scss”. As soon as I begin to use “SASS” code, the whole app crashes. Normal CSS works without problems.
Sass imports/partials, which are:
files that are prefixed with an underscore _
marked as isImport: true in the package’s package.js file: api.addFiles(‘x.scss’, ‘client’, {isImport: true}) Starting from Meteor 1.3, all files in a directory named imports/
The source files are compiled automatically (eagerly loaded). The imports are not loaded by themselves; you need to import them from one of the source files to use them.
If I understand it right, I have to create a client/imports.scss file and include any .scss file from imports in it. Mhhh…not really a satisfying solution.
Oh, and you import it in Javascript file or in other .scss file. For now in Meteor you can’t import .scss files in your javascript files. But if you import it from imports folder in another .scss file outside imports folder it should work.
Heads up for anyone with the issue still, I just had this issue and it looks like .scss javascript imports are now supported in the fourseven/meteor-scss package.
There is no need to provide the reference of stylesheets in the meteor. Just put your CSS file in client/stylesheets folder. Meteor will automatically apply these CSS rules.