Skip to content

Commit

Permalink
Fix Chunk.modules DeprecationWarning in Webpack 3.x
Browse files Browse the repository at this point in the history
Updates to Chunk.mapModules is not backwards compatible with Webpack 2.x due to breaking changes in webpack/webpack#4764

Following should be added to `README`:

### Install
```
# for webpack 3
npm install --save-dev extract-text-webpack-plugin
# for webpack 1, 2
npm install --save-dev extract-text-webpack-plugin@0.1.0
```
  • Loading branch information
steven-prybylynskyi committed Jul 20, 2017
1 parent 5e04244 commit a6865cc
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions Plugin.js
@@ -1,8 +1,9 @@
'use strict';

class ExtractFilePlugin {

apply(compiler) {

compiler.plugin('this-compilation', (compilation) => {

compilation.plugin('normal-module-loader', (loaderContext, module) => {
loaderContext[__dirname] = () => {
module.meta[__dirname] = true;
Expand All @@ -11,7 +12,7 @@ class ExtractFilePlugin {

compilation.plugin('additional-assets', callback => {
compilation.chunks.forEach(chunk => {
chunk.modules.forEach(module => processModule(chunk, module));
chunk.forEachModule(module => processModule(chunk, module));
});

callback();
Expand All @@ -21,22 +22,28 @@ class ExtractFilePlugin {
}

function processModule(chunk, ourModule) {

if (ourModule.meta && ourModule.meta[__dirname]) {

let moduleFound = false;

// let's find module, which was issued by ours (proxied module)
chunk.modules.some((module) => {
if (module.reasons.some(reason => reason.module === ourModule)) {
chunk.forEachModule((module) => {

if (!moduleFound && module.reasons.some(reason => reason.module === ourModule)) {
// add assets from that module
addAssets(chunk, module);
// break cycle
return true;
moduleFound = true;
}
});
}
}

function addAssets(chunk, module) {

// add any emitted assets via proxied module to this chunk
for (var file in module.assets) {
for (let file in module.assets) {
chunk.files.push(file);
}
}
Expand Down

0 comments on commit a6865cc

Please sign in to comment.