-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1.3] Style files imports from node_modules #6037
Comments
This is definitely an interesting feature to consider. Right now this won't work because only I'm going to leave this issue open but remove it from the Meteor 1.3 milestone for now, because I'm doubtful we will have a solution for this by the time we release 1.3 (but perhaps as soon as ~1.3.1). |
Ok, thanks. |
Okay, some context: Currently Meteor feeds entry-point (=non-imports) .scss files into our compile plugin (fourseven:scss). Most of the code of our plugin is about handling imports (with respect to cross-package imports etc.). Some limitations of node-sass/libsass make this a bit harder than for stylus/less. If I understand correctly (warning: I haven't looked into meteor 1.3) 2 things should change:
|
I don't know exactly how it works internally, but I think we need to treat So if now I can do This is how I understand it, but I don't know exactly how Meteor treats node_modules dir in v1.3 and how fourseven:scss works. |
I've been able to come to somewhat of a solution using
Then you can import them in your scss file by |
@thatgibbyguy cool! It should be enought for now, but I think that imports from |
One of the reasons I was hesitant to include anything other than It occurs to me that there is a middle ground: we could allow any files in direct If we do that, then if you want to import a non-JS file from a package in |
@benjamn Yeah, an alternative would be like this:
|
@benjamn yeah, it would be great. Also I wonder if we want to import other files than Also I hope that something like importing the file which imports another file from the same level 'node_modules' will still work. But this is probably In the future it'll be cool to have something like Webpack's css and images loaders, also CSS Modules. To build better separation of components. But this is for the future I gues). |
@thatgibbyguy is your scss.json file support to get it working with the current beta-5 build of Meteor? It still acts like it can't find the file to import when I try it. |
@queso there is one caveat with So what this means is comment out your imports in your main sass file and restart meteor. After that your imports should work fine. |
@queso It was done like that because in the past motion-ui was required by some of foundation's js plugins and there wasn't a simple way to include it. Now it isn't required. So I gues that Foundation team will wait for Meteor 1.3 official release. Because for now there isn't a clear path what should be done. Personally I prefer abandon |
@juliancwirko yeah, I saw that, and I agree that the proper way forward is to use the npm version because it will reduce load on outside projects having to care how Meteor compiles and/or packages files. |
@thatgibbyguy sorry to be dense, but I added the scss.json file to the root of my 1.3 app and restarted everything. Still no luck:
My main.scss file is just this:
|
I think @thatgibbyguy uses the old meter-scss (v1.2) plugin. Because later versions don't use scss.json anymore. That old version kind of bypasses the meteor compiler system and just reads the files from disk itself. It also doesn't support cross-package references. |
@sebakerckhof is right. I'm using |
@thatgibbyguy Yeah, 3.2 is what I meant to say. The changes I describe are from 3.3 up. |
IMO we really need a solution for this. I'm trying to use materialize-css with material-ui (NPM) and not having any luck. I either have to include materialize-css via HTML, which causes collisions with material-ui, or add the meteor package which has the same problem. I just want to be able to use |
Meteor 1.3 is almost Right now I'm trying a 1.3 project integration with https://github.com/thereactivestack/meteor-webpack only for import .scss files from Please MDG make a last effort on this ... |
If the second option above does not work then I think maybe it would make sense to focus the conversation on your #6846 and see if we can get this fixed or implemented as a new feature. |
@benjamn I like @thatgibbyguy's suggestion, relative to the app root, but absolute paths could point anywhere: {
"includePaths": [
"node_modules/some/path/"
]
} Are you guys averse to allowing some sort of configuration like this? |
Hi, |
@wimvanloocke importing .css file in .js file adds the contents of that .css file to the |
Maybe your right but i don't want to mess up and use a lot of different methods. Why does it work for imports of bootstrap, adminlte,.. and not for font-awesome,... do i miss an import / dependency. Is font-awesome not "build" for using this way? |
If you place the font files in public/fonts and the library that you want to use is using an absolute route like
So basically, there's no easy way right now to import source files from npm packages that involve css and font files (or something different than less, sass or stylus), especially when they are using relative paths on @imports. In those cases, atmosphere packages like |
If you have sym links to npm's font folders in the public folder, then meteor would not serve any static files (img & fonts) under public. May be a bug? You have to copy the npm's fonts folder to public & have it referenced as /fonts to work. |
@benjamn I'm not sure this issue should be closed. From what I understand you closed this because meteor now allows importing css files via javascript into To me it feels like a hack at best and not a great developer experience (why import all of our styles in |
Still getting:
|
Edit: Anyone fix this? I'm on 1.4.2.3 and importing css files doesn't work from node_modules(I'm not talking less or sass). I was convinced I was doing something wrong, so I copied the file to my own file and, magic, it works :( But I'm trying to use bootstrap, and copying all stylesheets kind of defeats the purpose. Am I doing something wrong and y'all fixed it? Should I do a package.js file? This is my absolute first app and I seriously have no idea what I'm doing... |
Haven't found a solution to importing a .css file through another CSS file. I'm not happy either about having to import it via a JS file. |
is this feature (import css from node modules) implemented in any release of meteor? |
@dandv - yes with 1.6 it's much easier. I've recently started playing around with it and I'll show you how it's done. After updating meteor
Simple as that. (note, this is with the latest |
@thatgibbyguy: I'm on Meteor 1.6.1 and I've Added this to client/main.css but in DevTools I see that meteor serves / instead of the CSS:
If I add this to main.js, the CSS does load:
|
I'm also importing in the main.js. @dandv have you tried with postcss? #6846 (comment) It has not yet been solved completely but seems to help in some cases. They migrated this to the feature request repository now: meteor/meteor-feature-requests#278 |
Although there was a comment in this code about not applying .meteorignore files to the contents of node_modules directories, I'm pretty sure that was the wrong decision, because .meteorignore merely limits what Meteor tries to compile as application code, and does not actually modify or hide node_modules files from other parts of Meteor (or Node). In other words, there's no harm in letting .meteorignore apply to node_modules, and there may be a LOT of benefit, because it allows the developer to fight back when compilation descends unexpectedly into an npm package that contains non-.js[on] files for which a compiler plugin has been registered, an obscure but not uncommon behavior originally intended to allow importing CSS assets from npm packages: * #6037 * 43659ff * a073280 * #5242 * #6846 * #7406 However, we now have a much more powerful tool for selectively compiling specific npm packages: #9771. In light of this new approach, we should probably remove the promiscuous node_modules compilation behavior altogether, as it might speed up rebuild times for many applications whose developers don't know or care that this behavior exists. For example, abandoning this behavior would prevent the problem reported here: #6950 In the meantime, this commit makes .meteorignore work for node_modules.
…es. (#9800) Although there was a comment in this code about not applying .meteorignore files to the contents of node_modules directories, I'm pretty sure that was the wrong decision, because .meteorignore merely limits what Meteor tries to compile as application code, and does not actually modify or hide node_modules files from other parts of Meteor (or Node). In other words, there's no harm in letting .meteorignore apply to node_modules, and there may be a LOT of benefit, because it allows the developer to fight back when compilation descends unexpectedly into an npm package that contains non-.js[on] files for which a compiler plugin has been registered, an obscure but not uncommon behavior originally intended to allow importing CSS assets from npm packages: * #6037 * 43659ff * a073280 * #5242 * #6846 * #7406 However, we now have a much more powerful tool for selectively compiling specific npm packages: #9771. In light of this new approach, we should probably remove the promiscuous node_modules compilation behavior altogether, as it might speed up rebuild times for many applications whose developers don't know or care that this behavior exists. For example, abandoning this behavior would prevent the problem reported here: #6950 In the meantime, this commit makes .meteorignore work for node_modules.
I made a PR with CSS imports working with POSTCSS in this Meteor React boilerplate from @juliancwirko. If you're having trouble making it work, take a look. It has the SCSS preprocessor working along with the POSTCSS as well. |
I've tried every option and workaround on this thread and nothing ain't working. Seems like a whole pile of doggy doo to me, npm packages from all over incorporate their own css which you need to import (and yes I mean css, not scss), and yet it seems MDG have ignored it despite getting all excited about whether it would make version 1.3 or have to wait until the first patch two-and-a-half years ago ??! |
@andrewlorenz I've got it working just fine. Here's what I've got:
In
Of course you may be using vanilla css and I wouldn't know how to incorporate that other than putting it in public and just writing vanilla css in client. Seems like you could have two working options here. |
Hi all, please see @livimonte 's comment above. For vanilla CSS, not SCSS or LESS, you should import it from your Here's an example of a
Using Please do some research before spamming the issue boards, it's even in the official guide! |
How to import .scss files located in the installed npm package (in node_modules). For example I do:
And now I want to import
.scss
files fromnode_modules/foundation-sites
I mean something like (in main.scss in the app):
I've tried many combinations, like
{}/node_modules/foundation-sites...
,{}/foundation-sites...
,/node_modules/foundation-sites...
, etc.Nothing works with
fourseven:scss
.Do we have a solution for this in Meteor 1.3? I gues that
node_modules
is ignored so .scss compiler doesn't see the files. I think this is the use case when compiler should see node_modules folder.The text was updated successfully, but these errors were encountered: