forked from mariusbalcytis/extract-file-loader
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
Chunk.modules
DeprecationWarning in Webpack 3.x
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
1 parent
5e04244
commit 1c8a04f
Showing
1 changed file
with
41 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,51 @@ | ||
'use strict'; | ||
|
||
class ExtractFilePlugin { | ||
apply(compiler) { | ||
compiler.plugin('this-compilation', (compilation) => { | ||
compilation.plugin('normal-module-loader', (loaderContext, module) => { | ||
loaderContext[__dirname] = () => { | ||
module.meta[__dirname] = true; | ||
}; | ||
}); | ||
|
||
compilation.plugin('additional-assets', callback => { | ||
compilation.chunks.forEach(chunk => { | ||
chunk.modules.forEach(module => processModule(chunk, module)); | ||
}); | ||
|
||
callback(); | ||
}); | ||
}); | ||
} | ||
|
||
apply(compiler) { | ||
|
||
compiler.plugin('this-compilation', (compilation) => { | ||
|
||
compilation.plugin('normal-module-loader', (loaderContext, module) => { | ||
loaderContext[__dirname] = () => { | ||
module.meta[__dirname] = true; | ||
}; | ||
}); | ||
|
||
compilation.plugin('additional-assets', callback => { | ||
compilation.chunks.forEach(chunk => { | ||
chunk.forEachModule(module => processModule(chunk, module)); | ||
}); | ||
|
||
callback(); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
function processModule(chunk, ourModule) { | ||
if (ourModule.meta && ourModule.meta[__dirname]) { | ||
// let's find module, which was issued by ours (proxied module) | ||
chunk.modules.some((module) => { | ||
if (module.reasons.some(reason => reason.module === ourModule)) { | ||
// add assets from that module | ||
addAssets(chunk, module); | ||
// break cycle | ||
return true; | ||
} | ||
}); | ||
} | ||
|
||
if (ourModule.meta && ourModule.meta[__dirname]) { | ||
|
||
let moduleFound = false; | ||
|
||
// let's find module, which was issued by ours (proxied module) | ||
chunk.forEachModule((module) => { | ||
|
||
if (!moduleFound && module.reasons.some(reason => reason.module === ourModule)) { | ||
// add assets from that module | ||
addAssets(chunk, module); | ||
// break cycle | ||
moduleFound = true; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
function addAssets(chunk, module) { | ||
// add any emitted assets via proxied module to this chunk | ||
for (var file in module.assets) { | ||
chunk.files.push(file); | ||
} | ||
|
||
// add any emitted assets via proxied module to this chunk | ||
for (let file in module.assets) { | ||
chunk.files.push(file); | ||
} | ||
} | ||
|
||
module.exports = ExtractFilePlugin; |