-
Notifications
You must be signed in to change notification settings - Fork 512
Conversation
I adjusted the extraction logic, the result is now as expected, however another test ( |
ok, ignore the last commit, does not make any sense and is not working at all. |
Codecov Report
@@ Coverage Diff @@
## master #546 +/- ##
=========================================
Coverage ? 88.37%
=========================================
Files ? 7
Lines ? 327
Branches ? 71
=========================================
Hits ? 289
Misses ? 36
Partials ? 2
Continue to review full report at Codecov.
|
I think I finally found the correct way to do it. It was a little hard to get my head around it without much docs about the webpack internals, but I think it's a proper solution. I will now actually keep the fallback loader in place for the async bundles and only rebuild it without replacing it in the async chunks. That means all css is correctly async loaded and only the css for the initial chunk is written down (if The initial chunks is freed from all dependencies and replaced with the generated module (that may contain the css-module informations). |
- merged with webpack-contrib/extract-text-webpack-plugin#546 - readded async css file reload - cleanup
Fixes #120 |
@BowlingX WoW..😧 😛 . I'm not 💯 skilled to answer if this is suitable or not, but it looks very good |
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.
It's too complex for me to review properly. Better get Tobias on this.
@BowlingX please squash all commits in one for easy review, thanks |
commit e2631af Author: David Heidrich <[email protected]> Date: Mon Jun 19 19:08:13 2017 +0200 removed dead code, cleanup commit d8943d7 Author: David Heidrich <[email protected]> Date: Mon Jun 19 15:48:51 2017 +0200 restored console log commit 0d7c94a Author: David Heidrich <[email protected]> Date: Mon Jun 19 00:30:34 2017 +0200 fixed async loading (keep original style loader in async chunks) commit 950d7ef Author: David Heidrich <[email protected]> Date: Sun Jun 18 15:52:41 2017 +0200 fixed exporting module informations commit 8b97ee5 Author: David Heidrich <[email protected]> Date: Sun Jun 18 14:27:51 2017 +0200 fixed line length commit 6898aa4 Author: David Heidrich <[email protected]> Date: Sun Jun 18 14:26:34 2017 +0200 respect all chunks commit bbc93ab Author: David Heidrich <[email protected]> Date: Sun Jun 18 12:33:09 2017 +0200 adjusted test to be env agnostic commit 3eba627 Author: David Heidrich <[email protected]> Date: Sun Jun 18 12:25:16 2017 +0200 adjusted tests to use css-loader, added tests for allChunks, remove module from initial chunk commit 09ac8cb Author: David Heidrich <[email protected]> Date: Sat Jun 17 22:36:09 2017 +0200 adjusted tests, remove module from base if extracted commit 1791796 Author: David Heidrich <[email protected]> Date: Sat Jun 17 21:23:58 2017 +0200 added testcase for issue webpack-contrib#120
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.
Should we be targeting master with this or the feature/webpack3
. This PR is wasted putting it in the current version range as it's only applicable to Webpack v2
We can always back port it to the 2.x version range after the fact. |
Seems like vue is handling async css loading on it's own. I think this get's in the way how extrac-text-webpack-plugin and my changes are doing this right now. So I would not expect that to be working together. |
@BowlingX @michael-ciniawsky @sokra @d3viant0ne @BowlingX Unfortunately there isn't activity in https://github.com/vuejs/vue-style-loader, ok, I'll try to create issue there (vue-style-loader repo). @michael-ciniawsky @sokra @d3viant0ne |
What is the status for this pull-request? Is there any more work needed? |
I was able to reproduce the issue that @nikit-cpp had. Something is not right here, I will investigate |
@BowlingX I can check if need |
The approach looks fine so far (from what i can tell :)) but as mentioned before I can't fully approve the changes. @sokra needs to review this PR to ensure this doesn't break the plugin |
src/index.js
Outdated
@@ -26,7 +27,7 @@ class ExtractTextPlugin { | |||
if (isString(options)) { | |||
options = { filename: options }; | |||
} else { | |||
validateOptions(path.resolve(__dirname, '../schema/plugin.json'), options, 'Extract Text Plugin'); | |||
validateOptions(path.resolve(__dirname, './schema/plugin.json'), options, 'Extract Text 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.
Why?
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.
./schema is not resolved correctly when I build the branch from source. Not sure how the build process is, but without changing the path it does not compile.
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 should be reverted and the schema folder moved back to where it was.
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.
Ideally move schema/Plugin.json && schema/loader.json
from /schema
to /src/Plugin.json
&& /src/loader.json
and add --copy-files
to the build
script in package.json
please.
- schema
src
||– index.js
||– Plugin.json
||- loader.js
||- loader.json
|
|-package.json
src/index.js
Outdated
@@ -40,6 +41,17 @@ class ExtractTextPlugin { | |||
return { loader: require.resolve('./loader'), options }; | |||
} | |||
|
|||
static cloneModule(module) { |
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.
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
src/index.js
Outdated
@@ -145,25 +159,38 @@ class ExtractTextPlugin { | |||
const extractedChunk = extractedChunks[chunks.indexOf(chunk)]; | |||
const shouldExtract = !!(options.allChunks || isInitialOrHasNoParents(chunk)); | |||
chunk.sortModules(); | |||
async.forEach(chunk.mapModules(c => c), (module, callback) => { // eslint-disable-line no-shadow | |||
async.forEach(chunk.mapModules((c) => { return c; }), (module, callback) => { // eslint-disable-line no-shadow, arrow-body-style |
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.
Why?
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.
can be changed to c => c
, properly a missed merge
does this have any more traction ? run some local tests with the forked branch and seems ok |
+1 |
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 had to use this here at my company because of the issue this is solving. Works fine so far.
The PR lgtm only the schema folder should be moved back to where it was imho and the stuff that was mentioned by others.
src/index.js
Outdated
@@ -26,7 +27,7 @@ class ExtractTextPlugin { | |||
if (isString(options)) { | |||
options = { filename: options }; | |||
} else { | |||
validateOptions(path.resolve(__dirname, '../schema/plugin.json'), options, 'Extract Text Plugin'); | |||
validateOptions(path.resolve(__dirname, './schema/plugin.json'), options, 'Extract Text 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.
This should be reverted and the schema folder moved back to where it was.
src/index.js
Outdated
@@ -88,7 +100,7 @@ class ExtractTextPlugin { | |||
if (Array.isArray(options) || isString(options) || typeof options.options === 'object' || typeof options.query === 'object') { | |||
options = { use: options }; | |||
} else { | |||
validateOptions(path.resolve(__dirname, '../schema/loader.json'), options, 'Extract Text Plugin (Loader)'); | |||
validateOptions(path.resolve(__dirname, './schema/loader.json'), options, 'Extract Text Plugin (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.
Should also be reverted.
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.
If I run the tests with ../schema
I get:
ENOENT: no such file or directory, open '/home/david/Projekte/extract-text-webpack-plugin/schema/loader.json'
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.
Because you moved the schema
folder into the src
folder, but @michael-ciniawsky wants to have them in a different location anyway, see other comment.
I will do the suggested changes and solve the conflicts today. |
# Conflicts: # src/index.js
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.
Only whitespace nits. Could you also move the various eslint-disable-line
comments to the top please ?
/* eslint-disable
...,
...,
*/
src/index.js
Outdated
@@ -26,7 +27,7 @@ class ExtractTextPlugin { | |||
if (isString(options)) { | |||
options = { filename: options }; | |||
} else { | |||
validateOptions(path.resolve(__dirname, '../schema/plugin.json'), options, 'Extract Text Plugin'); | |||
validateOptions(path.resolve(__dirname, './schema/plugin.json'), options, 'Extract Text 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.
Ideally move schema/Plugin.json && schema/loader.json
from /schema
to /src/Plugin.json
&& /src/loader.json
and add --copy-files
to the build
script in package.json
please.
- schema
src
||– index.js
||– Plugin.json
||- loader.js
||- loader.json
|
|-package.json
@@ -126,8 +127,10 @@ class ExtractTextPlugin { | |||
const filename = this.filename; | |||
const id = this.id; | |||
let extractedChunks; | |||
let toRemoveModules; |
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.
\n
src/index.js
Outdated
compilation.plugin('optimize-tree', (chunks, modules, callback) => { | ||
extractedChunks = chunks.map(() => new Chunk()); | ||
toRemoveModules = []; |
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.
\n
src/index.js
Outdated
let meta = module[NS]; | ||
if (meta && (!meta.options.id || meta.options.id === id)) { | ||
const wasExtracted = Array.isArray(meta.content); | ||
// A stricter `shouldExtract !== wasExtracted` check to guard against cases where a previously extracted | ||
// module would be extracted twice. Happens when a module is a dependency of an initial and a non-initial | ||
// chunk. See issue #604 | ||
if (shouldExtract && !wasExtracted) { | ||
module[`${NS}/extract`] = shouldExtract; // eslint-disable-line no-path-concat | ||
compilation.rebuildModule(module, (err) => { | ||
const newModule = cloneModule(module); |
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.
\n
src/index.js
Outdated
module[`${NS}/extract`] = shouldExtract; // eslint-disable-line no-path-concat | ||
compilation.rebuildModule(module, (err) => { | ||
const newModule = cloneModule(module); | ||
newModule[`${NS}/extract`] = shouldExtract; // eslint-disable-line no-path-concat |
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.
\n
src/index.js
Outdated
const data = toRemoveModules[module.identifier()]; | ||
if (data) { | ||
const oldModuleId = module.id; | ||
const newModule = cloneModule(module); |
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.
\n
const oldModuleId = module.id; | ||
const newModule = cloneModule(module); | ||
newModule.id = oldModuleId; | ||
newModule._source = data.module._source; // eslint-disable-line no-underscore-dangle |
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.
\n
newModule.id = oldModuleId; | ||
newModule._source = data.module._source; // eslint-disable-line no-underscore-dangle | ||
data.chunks.forEach((chunk) => { | ||
chunk.removeModule(data.moduleToRemove); |
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.
\n
newModule._source = data.module._source; // eslint-disable-line no-underscore-dangle | ||
data.chunks.forEach((chunk) => { | ||
chunk.removeModule(data.moduleToRemove); | ||
const deps = data.moduleToRemove.dependencies; |
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.
\n
if (d.module && d.module.loaders.length > 0) { | ||
chunk.removeModule(d.module); | ||
} | ||
}); |
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.
\n
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 good see @michael-ciniawsky note
I made the requested adjustments, Is there anything more needed here? The request is quite old, I'm wondering how to proceed here. |
# Conflicts: # src/index.js
@BowlingX Looks like we can close this PR, don't use |
@evilebottnawi I guess yes. I tested the new plugin and it works well for me. Also with the last changes (#604) my approach does not work anymore and I would have to refactor a bit. But properly it's unecessary because of the new plugin. |
This is a work-in-progress pull-request to address issue #120.
I added a test case to demonstrate the issue, use-case and my expectations.