Skip to content

Commit

Permalink
Merge pull request #72 from webpack-contrib/bugfix/incremental-build
Browse files Browse the repository at this point in the history
support incremental build
  • Loading branch information
sokra committed Mar 29, 2018
2 parents f379ee1 + 117b40d commit 7141c9a
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 126 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"nsp": "^3.1.0",
"pre-commit": "^1.2.2",
"standard-version": "^4.3.0",
"webpack": "^4.3.0",
"webpack": "^4.4.0",
"webpack-cli": "^2.0.13",
"webpack-defaults": "^1.6.0",
"webpack-dev-server": "^3.1.1"
Expand All @@ -56,7 +56,7 @@
"node": ">= 6.11.5"
},
"peerDependencies": {
"webpack": "^4.3.0"
"webpack": "^4.4.0"
},
"pre-commit": "lint-staged",
"lint-staged": {
Expand Down
35 changes: 35 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const NS = path.dirname(fs.realpathSync(__filename));

const pluginName = 'mini-css-extract-plugin';

const REGEXP_CHUNKHASH = /\[chunkhash(?::(\d+))?\]/i;
const REGEXP_CONTENTHASH = /\[contenthash(?::(\d+))?\]/i;
const REGEXP_NAME = /\[name\]/i;

class CssDependency extends webpack.Dependency {
constructor({ identifier, content, media, sourceMap }, context, identifierIndex) {
super();
Expand Down Expand Up @@ -61,6 +65,16 @@ class CssModule extends webpack.Module {
return resource;
}

updateCacheModule(module) {
this.content = module.content;
this.media = module.media;
this.sourceMap = module.sourceMap;
}

needRebuild() {
return true;
}

build(options, compilation, resolver, fileSystem, callback) {
this.buildInfo = {};
this.buildMeta = {};
Expand Down Expand Up @@ -131,6 +145,7 @@ class MiniCssExtractPlugin {
contentHashType: NS,
},
identifier: `mini-css-extract-plugin.${chunk.id}`,
hash: chunk.contentHash[NS],
});
}
});
Expand All @@ -145,9 +160,29 @@ class MiniCssExtractPlugin {
contentHashType: NS,
},
identifier: `mini-css-extract-plugin.${chunk.id}`,
hash: chunk.contentHash[NS],
});
}
});
compilation.mainTemplate.hooks.hashForChunk.tap(
pluginName,
(hash, chunk) => {
const { chunkFilename } = this.options;
if (REGEXP_CHUNKHASH.test(chunkFilename)) {
hash.update(JSON.stringify(chunk.getChunkMaps(true).hash));
}
if (REGEXP_CONTENTHASH.test(chunkFilename)) {
hash.update(
JSON.stringify(
chunk.getChunkMaps(true).contentHash[NS] || {},
),
);
}
if (REGEXP_NAME.test(chunkFilename)) {
hash.update(JSON.stringify(chunk.getChunkMaps(true).name));
}
},
);
compilation.hooks.contentHash.tap(pluginName, (chunk) => {
const { outputOptions } = compilation;
const { hashFunction, hashDigest, hashDigestLength } = outputOptions;
Expand Down
2 changes: 2 additions & 0 deletions test/manual/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const Self = require('../../');
module.exports = {
mode: 'development',
output: {
chunkFilename: "[contenthash].js",
publicPath: '/dist/',
},
module: {
Expand All @@ -19,6 +20,7 @@ module.exports = {
plugins: [
new Self({
filename: '[name].css',
chunkFilename: "[contenthash].css",
}),
],
devServer: {
Expand Down
Loading

0 comments on commit 7141c9a

Please sign in to comment.