Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit be7936d

Browse files
authored
refactor: Update deprecated chunk.modules functions (#553)
- refactor: Replace usage of chunk.modules with forEachModule, mapModules ect.. BREAKING CHANGE: Updates to `Chunk.mapModules | forEachModule | getNumberOfModules`. This release is not backwards compatible with `Webpack 2.x` due to breaking changes in webpack/webpack#4764
1 parent 10721f5 commit be7936d

File tree

8 files changed

+29
-6
lines changed

8 files changed

+29
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"node": ">= 4.3 < 5.0.0 || >= 5.10"
6262
},
6363
"peerDependencies": {
64-
"webpack": "^3.0.0"
64+
"webpack": "^3.1.0"
6565
},
6666
"homepage": "http://github.com/webpack-contrib/extract-text-webpack-plugin",
6767
"repository": {

src/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ExtractTextPlugin {
6464
}, this);
6565
} else if (checkedChunks.indexOf(chunk) < 0) {
6666
checkedChunks.push(chunk);
67-
chunk.modules.slice().forEach((module) => {
67+
chunk.forEachModule((module) => {
6868
intoChunk.addModule(module);
6969
module.addChunk(intoChunk);
7070
});
@@ -77,7 +77,7 @@ class ExtractTextPlugin {
7777

7878
renderExtractedChunk(chunk) {
7979
const source = new ConcatSource();
80-
chunk.modules.forEach((module) => {
80+
chunk.forEachModule((module) => {
8181
const moduleSource = module.source();
8282
source.add(this.applyAdditionalInformation(moduleSource, module.additionalInformation));
8383
}, this);
@@ -144,7 +144,8 @@ class ExtractTextPlugin {
144144
async.forEach(chunks, (chunk, callback) => { // eslint-disable-line no-shadow
145145
const extractedChunk = extractedChunks[chunks.indexOf(chunk)];
146146
const shouldExtract = !!(options.allChunks || isInitialOrHasNoParents(chunk));
147-
async.forEach(chunk.mapModules((c) => { return c; }), (module, callback) => { // eslint-disable-line no-shadow, arrow-body-style
147+
chunk.sortModules();
148+
async.forEach(chunk.mapModules(c => c), (module, callback) => { // eslint-disable-line no-shadow
148149
let meta = module[NS];
149150
if (meta && (!meta.options.id || meta.options.id === id)) {
150151
const wasExtracted = Array.isArray(meta.content);
@@ -181,7 +182,7 @@ class ExtractTextPlugin {
181182
}, this);
182183
extractedChunks.forEach((extractedChunk) => {
183184
if (!isInitialOrHasNoParents(extractedChunk)) {
184-
extractedChunk.modules.slice().forEach((module) => {
185+
extractedChunk.forEachModule((module) => {
185186
extractedChunk.removeModule(module);
186187
});
187188
}
@@ -192,7 +193,7 @@ class ExtractTextPlugin {
192193
});
193194
compilation.plugin('additional-assets', (callback) => {
194195
extractedChunks.forEach((extractedChunk) => {
195-
if (extractedChunk.modules.length) {
196+
if (extractedChunk.getNumberOfModules()) {
196197
extractedChunk.modules.sort((a, b) => {
197198
if (!options.ignoreOrder && isInvalidOrder(a, b)) {
198199
compilation.errors.push(new OrderUndefinedError(a.getOriginalModule()));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('./c.txt');
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.block {
2+
color: tomato;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.App {
2+
color: black;
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.block {
2+
color: tomato;
3+
}
4+
.App {
5+
color: black;
6+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require('./a');
2+
require('./b.txt');
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var ExtractTextPlugin = require("../../../");
2+
module.exports = {
3+
entry: "./index",
4+
plugins: [
5+
new ExtractTextPlugin("file.css")
6+
]
7+
};

0 commit comments

Comments
 (0)