-
Notifications
You must be signed in to change notification settings - Fork 214
Enable CSS Modules by default in *.module.css files #495
Conversation
@eliperelman will do! |
@eliperelman not sure what I'm missing…but can't get your PR working: As soon as I add a
Also tried disabling hot/extract just to debug, but got a similar error. .neutrinorc.js
src/index.js
If I remove |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we be setting options.css.modules
= options.modules
to actually enable modules in css-loader? https://github.com/webpack-contrib/css-loader#options
lol yup. I'll revise. |
@timkelty OK, should be fixed. |
packages/style-loader/index.js
Outdated
@@ -3,63 +3,92 @@ const merge = require('deepmerge'); | |||
|
|||
module.exports = (neutrino, opts = {}) => { | |||
const options = merge({ | |||
test: opts.modules !== false | |||
? /(?<!\.module)\.css$/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What version of node are you testing in?
It would seem negative lookbehinds don't work in node 8.x (they do in 9.x)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omg 🤣
OK, lemme get that fixed.
@timkelty OK, give that a shot. |
const isCssModule = cssModulesTest.test(input); | ||
const isRegularCss = cssTest.test(input); | ||
|
||
if (opts.modules !== false && isCssModule) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since opt.modules
is always just a bool, why not just do opts.modules && isCssModule
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, for some reason I had it in my head that it could be an object, but I guess that's not the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I know why: opts.modules
could be undefined, and in that case, it should be treated the same as true
, since that would be the default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah gotcha.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
See note about potentially setting ignoreOrder. Could go either way on it - just an idea.
fallback: { | ||
loader: styleEntries[options.styleUseId].get('loader'), | ||
options: styleEntries[options.styleUseId].get('options') | ||
if (options.modules) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something to consider here might be to set options.extract.plugin.ignoreOrder: options.modules
, just as a nice default: https://github.com/webpack-contrib/extract-text-webpack-plugin#options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooo nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrmm - ignoreOrder
is an option for options.extract.plugin
, not options.css
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yikes, sorry. :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be able to just do it up in the initial options
merge, eg
extract: {
plugin: {
filename: neutrino.options.command === 'build' ? '[name].[contenthash].css' : '[name].css',
ignoreOrder: opts.modules !== false
}
}
Thanks @timkelty for the great review! |
Fixes #440.
@timkelty would you be interested in having a look at this?