Skip to content

Commit

Permalink
Merge pull request #7399 from webpack/feat-implement-option-for-hashe…
Browse files Browse the repository at this point in the history
…d-module-ids-plugin

feat: implement option for `HashedModuleIdes` plugin
  • Loading branch information
sokra committed Jun 28, 2018
2 parents f41b829 + f6a86d8 commit dcf3e09
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/WebpackOptionsApply.js
Expand Up @@ -56,6 +56,7 @@ const RuntimeChunkPlugin = require("./optimize/RuntimeChunkPlugin");
const NoEmitOnErrorsPlugin = require("./NoEmitOnErrorsPlugin");
const NamedModulesPlugin = require("./NamedModulesPlugin");
const NamedChunksPlugin = require("./NamedChunksPlugin");
const HashedModuleIdsPlugin = require("./HashedModuleIdsPlugin");
const DefinePlugin = require("./DefinePlugin");
const SizeLimitsPlugin = require("./performance/SizeLimitsPlugin");
const WasmFinalizeExportsPlugin = require("./wasm/WasmFinalizeExportsPlugin");
Expand Down Expand Up @@ -354,6 +355,9 @@ class WebpackOptionsApply extends OptionsApply {
if (options.optimization.namedModules) {
new NamedModulesPlugin().apply(compiler);
}
if (options.optimization.hashedModuleIds) {
new HashedModuleIdsPlugin().apply(compiler);
}
if (options.optimization.namedChunks) {
new NamedChunksPlugin().apply(compiler);
}
Expand Down
1 change: 1 addition & 0 deletions lib/WebpackOptionsDefaulter.js
Expand Up @@ -263,6 +263,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
"make",
options => options.mode === "development"
);
this.set("optimization.hashedModuleIds", false);
this.set(
"optimization.namedChunks",
"make",
Expand Down
4 changes: 4 additions & 0 deletions schemas/WebpackOptions.json
Expand Up @@ -1554,6 +1554,10 @@
"description": "Use readable module identifiers for better debugging",
"type": "boolean"
},
"hashedModuleIds": {
"description": "Use hashed module id instead module identifiers for better long term caching",
"type": "boolean"
},
"namedChunks": {
"description": "Use readable chunk identifiers for better debugging",
"type": "boolean"
Expand Down
1 change: 1 addition & 0 deletions test/TestCases.template.js
Expand Up @@ -29,6 +29,7 @@ const DEFAULT_OPTIMIZATIONS = {
noEmitOnErrors: false,
concatenateModules: false,
namedModules: false,
hashedModuleIds: false,
minimizer: [uglifyJsForTesting]
};

Expand Down
@@ -0,0 +1 @@
module.exports = module.id;
@@ -0,0 +1 @@
module.exports = module.id;
@@ -0,0 +1 @@
module.exports = module.id;
@@ -0,0 +1 @@
module.exports = module.id;
@@ -0,0 +1 @@
module.exports = module.id;
7 changes: 7 additions & 0 deletions test/configCases/optimization/hashed-module-ids/index.js
@@ -0,0 +1,7 @@
it("should have named modules ids", function() {
for (var i = 1; i <= 5; i++) {
var moduleId = require("./files/file" + i + ".js");

expect(moduleId).toMatch(/^[/=a-zA-Z0-9]{4,5}$/);
}
});
@@ -0,0 +1,5 @@
module.exports = {
optimization: {
hashedModuleIds: true
}
};
1 change: 1 addition & 0 deletions test/configCases/optimization/named-modules/files/file1.js
@@ -0,0 +1 @@
module.exports = module.id;
1 change: 1 addition & 0 deletions test/configCases/optimization/named-modules/files/file2.js
@@ -0,0 +1 @@
module.exports = module.id;
1 change: 1 addition & 0 deletions test/configCases/optimization/named-modules/files/file3.js
@@ -0,0 +1 @@
module.exports = module.id;
1 change: 1 addition & 0 deletions test/configCases/optimization/named-modules/files/file4.js
@@ -0,0 +1 @@
module.exports = module.id;
1 change: 1 addition & 0 deletions test/configCases/optimization/named-modules/files/file5.js
@@ -0,0 +1 @@
module.exports = module.id;
10 changes: 10 additions & 0 deletions test/configCases/optimization/named-modules/index.js
@@ -0,0 +1,10 @@
var path = require("path");

it("should have named modules ids", function() {
for (var i = 1; i <= 5; i++) {
var expectedModuleId = "file" + i + ".js";
var moduleId = require("./files/file" + i + ".js");

expect(path.basename(moduleId)).toBe(expectedModuleId);
}
});
5 changes: 5 additions & 0 deletions test/configCases/optimization/named-modules/webpack.config.js
@@ -0,0 +1,5 @@
module.exports = {
optimization: {
namedModules: true
}
};

0 comments on commit dcf3e09

Please sign in to comment.