survivejs / webpack-book

From apprentice to master (CC BY-NC-ND)
https://survivejs.com/webpack/
2.42k stars 319 forks source link

Separating CSS chapter - Can't resolve 'app/main.css' #135

Closed jeggett closed 7 years ago

jeggett commented 7 years ago

In section "Managing Styles Outside of JavaScript" after configuring everything according to this section I got following error.

ERROR in multi style
Module not found: Error: Can't resolve 'app/main.css' in '/home/jeggett/WebstormProjects/webpack2_config'
 @ multi style

So in my project I changed this line:

style: glob.sync('app/**/*.css'),

from code listing to the following

style: path.join(__dirname, glob.sync('app/**/*.css')[0]),

to get rid of the error.

PS. Dumb question: Is it possible to get css-modules working without referncing to main.css from JS code? If I will not remove import './main.css'; from index.js would css-modules potentially work after some adjustments?

bebraw commented 7 years ago

Good catch. I think the glob we want is glob.sync('./app/**/*.css'). Think entries as regular imports.

PS. Dumb question: Is it possible to get css-modules working without referncing to main.css from JS code? If I will not remove import './main.css'; from index.js would css-modules potentially work after some adjustments?

CSS Modules effectively couple styling with JS. I don't see how else it could work.