Skip to content
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

import css file from node_modules? #352

Closed
hyalkaf opened this issue Aug 19, 2016 · 7 comments
Closed

import css file from node_modules? #352

hyalkaf opened this issue Aug 19, 2016 · 7 comments

Comments

@hyalkaf
Copy link

hyalkaf commented Aug 19, 2016

I was wondering what changes should I make to import css files from node_modules into my components? boilerplate only imports css files if they have .global.css or if they are in the same folder as js files.

@amilajack
Copy link
Member

Use sass instead. You can use my repo as an example:

https://github.com/amilajack/popcorn-time-desktop

Check out this webpack file

@csprance
Copy link

How does using sass solve the problem of importing css files? I have a similar issue in which i need to use ag-grid so i need to do a

import 'ag-grid/dist/styles/theme-fresh.css';
import 'ag-grid/dist/styles/ag-grid.css';

How would using sass solve that issue?

@hyalkaf
Copy link
Author

hyalkaf commented Aug 31, 2016

I solved it by adding this to my webpack.config.developement.js and webpack.config.production:

{
        test: /\.css$/,
        loader: "style-loader!css-loader"
}

This is probably not the optimal solution since this goes through all your CSS files under node_modules. For the specific files you mentioned, you might be able to do something like this:

{
        test: /ag-grid[\\\/]dist[\\\/]styles\.css$/,
        loader: "style-loader!css-loader"
}

@amilajack
Copy link
Member

Makes sense. Can this be closed?

@hyalkaf
Copy link
Author

hyalkaf commented Aug 31, 2016

Yeah sure. Unless @csprance have more questions.

@csprance
Copy link

csprance commented Sep 1, 2016

Yep feel free to close it. I didn't end up using any of the solutions here because they didn't seem to work.
My solution was to use the following code in app.global.css

@import '../node_modules/ag-grid/dist/styles/ag-grid.css';
@import '../node_modules/ag-grid/dist/styles/theme-dark.css';

this way it pulled only the css i needed from the specific themes needed

@hyalkaf hyalkaf closed this as completed Sep 1, 2016
@devsli
Copy link

devsli commented Sep 30, 2016

Other possible solution is to use .module.css to specify local module and treat all other files as global.

Source: webpack-contrib/css-loader#308

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants