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
  • Loading branch information
steven-prybylynskyi committed Jul 20, 2017
1 parent 5e04244 commit 3789db6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .gitignore
@@ -1,2 +1,4 @@
/.idea

/node_modules
/npm-debug.log
/npm-debug.log
21 changes: 15 additions & 6 deletions Plugin.js
@@ -1,8 +1,11 @@
'use strict';
'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 +14,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 +24,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
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -9,6 +9,15 @@ not added to the chunk files
- this loader is used as a proxy to include this emitted file in the chunk
so it's available in generated manifest

# Install

```bash
# 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
```

## Usage

```js
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "extract-file-loader",
"version": "0.1.0",
"version": "0.2.0",
"author": "Marius Balčytis",
"description": "Loader and plugin for webpack to add proxied asset as a chunk file",
"dependencies": {
Expand All @@ -11,7 +11,7 @@
"file-loader": "^0.8.4",
"image-webpack-loader": "^2.0.0",
"mocha": "^3.0.2",
"webpack": "^1.13.2"
"webpack": "^3"
},
"engines": {
"node": ">=4"
Expand Down

0 comments on commit 3789db6

Please sign in to comment.