-
Notifications
You must be signed in to change notification settings - Fork 214
Support extract-text for styles via options.extract #443
Conversation
packages/style-loader/index.js
Outdated
module.exports = ({ config }, options = {}) => config.module | ||
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | ||
const merge = require('deepmerge'); | ||
const { pick, mapValues } = require('lodash'); |
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.
We typically use ramda in place of lodash, so let's swap that out here, or use native implementations where possible.
packages/style-loader/index.js
Outdated
})); | ||
|
||
options.extract.loader = Object.assign({ | ||
use: Object.values(pick(loadersByKey, useKeys)), |
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.
Object.values isn't available in Node.js v6, so you'll have to map the values out:
Object.keys(object).map(key => object[key])
packages/style-loader/index.js
Outdated
}, options.extract.loader || {}); | ||
|
||
styleRule | ||
.uses |
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.
Add 2 more spaces of indentation.
packages/style-loader/index.js
Outdated
.when(options.cssHotLoader, use => use.options(options.cssHotLoader)); | ||
}); | ||
|
||
ExtractTextPlugin.extract(options.extract.loader) |
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.
Move .extract
to the next line, and increase its indent 2 spaces.
packages/style-loader/index.js
Outdated
ExtractTextPlugin.extract(options.extract.loader) | ||
.forEach(({ loader, options }) => { | ||
styleRule | ||
.use(loader) |
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.
Indent 2 more spaces.
packages/style-loader/index.js
Outdated
.options(options); | ||
}); | ||
|
||
neutrino.config.plugin('extract') |
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.
Move .plugin
to the next line and increase indent 2 spaces from the line above it.
packages/style-loader/index.js
Outdated
const isBuild = neutrino.options.command === 'start'; | ||
const options = merge({ | ||
styleUseId: 'style', | ||
cssHotLoaderUseId: 'cssHotLoader', |
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.
How would you feel about this just being hot
, similar to the hot
plugin?
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.
Sure. Do you mean the the option name (cssHotLoaderUseId
) or the value 'cssHotLoader'
?
Not sure if we even need it configurable as an option, was just following suit with options.styleUseId
, options.cssUseId
I think I've tidied up all the indentation from the review…the only one I wasn't sure about was > Move .extract to the next line, and increase its indent 2 spaces. This isn't a |
I refactored without lodash or ramda. If we end up wanting ramda, we'll probably just want |
I'm now passing I'm also now passing |
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.
This is great, I'm so happy to see this! Just one small nit, and we can merge!
packages/style-loader/index.js
Outdated
.clear() | ||
.end() | ||
.when(options.hot, (rule) => { | ||
rule.use(options.cssHotLoaderUseId || 'cssHotLoader') |
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.
Yeah, my comment before wasn't very clear, my apologies. I was asking to name this ID from cssHotLoader
to just hot
, just the HotPlugin does in other middleware.
@@ -24,6 +24,9 @@ module.exports = (neutrino, opts = {}) => { | |||
env: [], | |||
hot: true, | |||
html: {}, | |||
style: { | |||
hot: opts.hot !== false |
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.
😍
packages/image-loader/index.js
Outdated
@@ -13,7 +13,7 @@ module.exports = ({ config }, options = {}) => { | |||
|
|||
config.module | |||
.rule('img') | |||
.test(/\.(png|jpg|jpeg|gif)(\?v=\d+\.\d+\.\d+)?$/) | |||
.test(/\.(png|jpg|jpeg|gif|webp)(\?v=\d+\.\d+\.\d+)?$/) |
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.
Looks like the master commit got re-included here. You may want to:
git checkout master
git pull upstream master
git checkout style-loader-extract
git checkout HEAD~1
git rebase master
git commit -m "Pass options.hot instead of options.cssHotLoader" --amend
git push -f origin style-loader-extract
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.
Whups - yeah I rebased from master
@timkelty looks like the same thing happened to yargs 🤣 |
7b2b5a6
to
10ca3bc
Compare
@eliperelman ok, should just have commits for this PR now. Will this be for 8.x then? (currently would be breaking, only because |
Yep! Extraction itself is also breaking, since it would modify hashes of file output. |
Last thing, just for future reference - is this how you wanted this bit indented? https://github.com/timkelty/neutrino-dev/blob/10ca3bca6615bb8dae7bafe85dcdcd9a435d3586/packages/style-loader/index.js#L53-L60 I didn't expect you to want the |
@timkelty yes, my indentation preferences just rely on readability, method chaining, and context. |
Yikes, that fell through the cracks! b777bb5 |
Fixes #439
Notes:
options.extract = false