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

fix: split async CSS correctly #546

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
77daf83
refactor: pass a unique compiler name to get child compilation (#483)
sokra Jun 11, 2017
92e4349
chore(package): Update peerDeps & webpack devDep
joshwiens Jun 11, 2017
cdfccb4
Squashed commit of the following:
BowlingX Jun 20, 2017
3e78452
refactor: Apply webpack-defaults (#542)
joshwiens Jun 21, 2017
4880afb
Merge remote-tracking branch 'base/feature/webpack3'
BowlingX Jun 21, 2017
5df5d09
fix(tests): fixed test to work with webpack 3, adjusted dependencies
BowlingX Jun 21, 2017
b202f4a
only remove dependencies that have loaders defined
BowlingX Jun 21, 2017
292e217
refactor: Apply webpack-defaults (#542)
joshwiens Jun 21, 2017
28171b2
refactor: Chunk.modules deprecation warning
joshwiens Jun 23, 2017
1730d46
chore(release): 3.0.0-beta.0
joshwiens Jun 23, 2017
5d0c28f
fix: Distribute schema with package
joshwiens Jun 24, 2017
715b1dd
chore(release): 3.0.0-beta.1
joshwiens Jun 24, 2017
1ef755a
chore: Update install docs
joshwiens Jun 24, 2017
84a0328
chore(release): 3.0.0-beta.2
joshwiens Jun 24, 2017
b33e006
chore(package): Update deps minor versions
joshwiens Jun 24, 2017
d4a0c23
chore(release): 3.0.0-beta.3
joshwiens Jun 24, 2017
10721f5
chore: Update changelog for beta 1 & 2
joshwiens Jun 24, 2017
1175e63
Merge remote-tracking branch 'base/feature/webpack3'
BowlingX Jun 26, 2017
fb4eb9b
fixed merge conflicts
BowlingX Jun 26, 2017
400ed49
Merge branch 'master-remote'
BowlingX Jul 21, 2017
143760a
fixed tests
BowlingX Jul 21, 2017
163191a
Merge remote-tracking branch 'base/master'
BowlingX Nov 29, 2017
2ba04eb
adjusted tests
BowlingX Nov 29, 2017
3ef2916
adjusted tests
BowlingX Nov 29, 2017
8403a27
fixed code style, moved clone to helpers
BowlingX Nov 29, 2017
3aed4df
code style fixes
BowlingX Mar 18, 2018
f1a8ce2
moved schema files to src, adjusted build.
BowlingX Mar 18, 2018
edd39a1
Merge remote-tracking branch 'upstream/master'
BowlingX Apr 5, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -12,7 +12,7 @@
"scripts": {
"start": "npm run build -- -w",
"appveyor:test": "npm run test",
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js'",
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js' --copy-files",
"build:example": "(cd example && webpack)",
"clean": "del-cli dist",
"lint": "eslint --cache src test",
Expand Down
65 changes: 56 additions & 9 deletions src/index.js
Expand Up @@ -15,6 +15,7 @@ import {
mergeOptions,
isString,
isFunction,
cloneModule,
} from './lib/helpers';

const NS = path.dirname(fs.realpathSync(__filename));
Expand All @@ -26,7 +27,7 @@ class ExtractTextPlugin {
if (isString(options)) {
options = { filename: options };
} else {
validateOptions(path.resolve(__dirname, '../schema/plugin.json'), options, 'Extract Text Plugin');
validateOptions(path.resolve(__dirname, './plugin.json'), options, 'Extract Text Plugin');
}
this.filename = options.filename;
this.id = options.id != null ? options.id : ++nextId;
Expand Down Expand Up @@ -88,7 +89,7 @@ class ExtractTextPlugin {
if (Array.isArray(options) || isString(options) || typeof options.options === 'object' || typeof options.query === 'object') {
options = { use: options };
} else {
validateOptions(path.resolve(__dirname, '../schema/loader.json'), options, 'Extract Text Plugin (Loader)');
validateOptions(path.resolve(__dirname, './loader.json'), options, 'Extract Text Plugin (Loader)');
}
let loader = options.use;
let before = options.fallback || [];
Expand All @@ -115,7 +116,9 @@ class ExtractTextPlugin {
compilation.plugin('normal-module-loader', (loaderContext, module) => {
loaderContext[NS] = (content, opt) => {
if (options.disable) { return false; }
if (!Array.isArray(content) && content != null) { throw new Error(`Exported value was not extracted as an array: ${JSON.stringify(content)}`); }
if (!Array.isArray(content) && content != null) {
throw new Error(`Exported value was not extracted as an array: ${JSON.stringify(content)}`);
}
module[NS] = {
content,
options: opt || {},
Expand All @@ -126,8 +129,12 @@ class ExtractTextPlugin {
const filename = this.filename;
const id = this.id;
let extractedChunks;
let toRemoveModules;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\n


compilation.plugin('optimize-tree', (chunks, modules, callback) => {
extractedChunks = chunks.map(() => new Chunk());
toRemoveModules = [];

chunks.forEach((chunk, i) => {
const extractedChunk = extractedChunks[i];
extractedChunk.index = i;
Expand Down Expand Up @@ -161,24 +168,40 @@ class ExtractTextPlugin {
}
}
if (shouldExtract || (!module.extracted && !wasExtracted)) {
module[`${NS}/extract`] = true; // eslint-disable-line no-path-concat
compilation.rebuildModule(module, (err) => {
const newModule = cloneModule(module);
newModule[`${NS}/extract`] = shouldExtract; // eslint-disable-line no-path-concat
compilation.buildModule(newModule, false, newModule, null, (err) => {
if (err) {
compilation.errors.push(err);
return callback();
}
meta = module[NS];
meta = newModule[NS];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\n


const identifier = module.identifier();
// Error out if content is not an array and is not null
if (!Array.isArray(meta.content) && meta.content != null) {
err = new Error(`${module.identifier()} doesn't export content`);
err = new Error(`${identifier} doesn't export content`);
compilation.errors.push(err);
return callback();
}
if (meta.content) { extractCompilation.addResultToChunk(module.identifier(), meta.content, module, extractedChunk); }
if (meta.content) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\n (before)

extractCompilation.addResultToChunk(identifier, meta.content, module, extractedChunk);
if (toRemoveModules[identifier]) {
toRemoveModules[identifier].chunks.push(chunk);
} else {
toRemoveModules[identifier] = {
module: newModule,
moduleToRemove: module,
chunks: [chunk],
};
}
}
callback();
});
} else {
if (meta.content) { extractCompilation.addResultToChunk(module.identifier(), meta.content, module, extractedChunk); }
if (meta.content) {
extractCompilation.addResultToChunk(module.identifier(), meta.content, module, extractedChunk);
}
callback();
}
} else callback();
Expand All @@ -202,6 +225,30 @@ class ExtractTextPlugin {
callback();
});
});

compilation.plugin('optimize-module-ids', (modules) => {
modules.forEach((module) => {
const data = toRemoveModules[module.identifier()];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\n


if (data) {
const oldModuleId = module.id;
const newModule = cloneModule(module);
newModule.id = oldModuleId;
newModule._source = data.module._source; // eslint-disable-line no-underscore-dangle
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\n

data.chunks.forEach((chunk) => {
chunk.removeModule(data.moduleToRemove);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\n

const deps = data.moduleToRemove.dependencies;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\n

deps.forEach((d) => {
if (d.module && d.module.loaders.length > 0) {
chunk.removeModule(d.module);
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\n

chunk.addModule(newModule);
});
}
});
});

compilation.plugin('additional-assets', (callback) => {
extractedChunks.forEach((extractedChunk) => {
if (extractedChunk.getNumberOfModules()) {
Expand Down
13 changes: 13 additions & 0 deletions src/lib/helpers.js
@@ -1,3 +1,5 @@
import NormalModule from 'webpack/lib/NormalModule';

export function isInitialOrHasNoParents(chunk) {
return chunk.isInitial() || chunk.parents.length === 0;
}
Expand Down Expand Up @@ -28,6 +30,17 @@ export function getOrder(a, b) {
return 0;
}

export function cloneModule(module) {
return new NormalModule(
module.request,
module.userRequest,
module.rawRequest,
module.loaders,
module.resource,
module.parser,
);
}

export function getLoaderObject(loader) {
if (isString(loader)) {
return { loader };
Expand Down
File renamed without changes.
File renamed without changes.