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

Commit 9262804

Browse files
committed
refactor: Move non initial chunks to class method
1 parent fe166b7 commit 9262804

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/index.js

+31-31
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,35 @@ class ExtractTextPlugin {
5555
return ExtractTextPlugin.loader(mergeOptions({ id: this.id }, options));
5656
}
5757

58+
mergeNonInitialChunks(chunk, intoChunk, checkedChunks) {
59+
if (!intoChunk) {
60+
checkedChunks = [];
61+
chunk.chunks.forEach((c) => {
62+
if (isInitialOrHasNoParents(c)) return;
63+
this.mergeNonInitialChunks(c, chunk, checkedChunks);
64+
}, this);
65+
} else if (checkedChunks.indexOf(chunk) < 0) {
66+
checkedChunks.push(chunk);
67+
chunk.modules.slice().forEach((module) => {
68+
intoChunk.addModule(module);
69+
module.addChunk(intoChunk);
70+
});
71+
chunk.chunks.forEach((c) => {
72+
if (isInitialOrHasNoParents(c)) return;
73+
this.mergeNonInitialChunks(c, intoChunk, checkedChunks);
74+
}, this);
75+
}
76+
}
77+
78+
renderExtractedChunk(chunk) {
79+
const source = new ConcatSource();
80+
chunk.modules.forEach((module) => {
81+
const moduleSource = module.source();
82+
source.add(this.applyAdditionalInformation(moduleSource, module.additionalInformation));
83+
}, this);
84+
return source;
85+
}
86+
5887
extract(options) {
5988
if (Array.isArray(options) || isString(options) || typeof options.options === 'object' || typeof options.query === 'object') {
6089
options = { use: options };
@@ -192,35 +221,6 @@ class ExtractTextPlugin {
192221
}
193222
}
194223

195-
export default ExtractTextPlugin;
196-
197-
ExtractTextPlugin.prototype.mergeNonInitialChunks = function (chunk, intoChunk, checkedChunks) { // eslint-disable-line func-names
198-
if (!intoChunk) {
199-
checkedChunks = [];
200-
chunk.chunks.forEach((c) => {
201-
if (isInitialOrHasNoParents(c)) return;
202-
this.mergeNonInitialChunks(c, chunk, checkedChunks);
203-
}, this);
204-
} else if (checkedChunks.indexOf(chunk) < 0) {
205-
checkedChunks.push(chunk);
206-
chunk.modules.slice().forEach((module) => {
207-
intoChunk.addModule(module);
208-
module.addChunk(intoChunk);
209-
});
210-
chunk.chunks.forEach((c) => {
211-
if (isInitialOrHasNoParents(c)) return;
212-
this.mergeNonInitialChunks(c, intoChunk, checkedChunks);
213-
}, this);
214-
}
215-
};
216-
217-
ExtractTextPlugin.prototype.renderExtractedChunk = function (chunk) { // eslint-disable-line func-names
218-
const source = new ConcatSource();
219-
chunk.modules.forEach((module) => {
220-
const moduleSource = module.source();
221-
source.add(this.applyAdditionalInformation(moduleSource, module.additionalInformation));
222-
}, this);
223-
return source;
224-
};
225-
226224
ExtractTextPlugin.extract = ExtractTextPlugin.prototype.extract.bind(ExtractTextPlugin);
225+
226+
export default ExtractTextPlugin;

0 commit comments

Comments
 (0)