feat: implement option for `HashedModuleIdes` plugin

This commit is contained in:
evilebottnawi 2018-05-25 16:41:20 +03:00
parent b77addda16
commit c222a6f33b
18 changed files with 50 additions and 0 deletions

View File

@ -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");
@ -328,6 +329,8 @@ class WebpackOptionsApply extends OptionsApply {
new NoEmitOnErrorsPlugin().apply(compiler);
if (options.optimization.namedModules)
new NamedModulesPlugin().apply(compiler);
if (options.optimization.hashedModuleIds)
new HashedModuleIdsPlugin().apply(compiler);
if (options.optimization.namedChunks)
new NamedChunksPlugin().apply(compiler);
if (options.optimization.nodeEnv) {

View File

@ -258,6 +258,8 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
"make",
options => options.mode === "development"
);
// TODO enable for production mode in webpack 5
this.set("optimization.hashedModuleIds", false);
this.set(
"optimization.namedChunks",
"make",

View File

@ -1546,6 +1546,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"

View File

@ -29,6 +29,7 @@ const DEFAULT_OPTIMIZATIONS = {
noEmitOnErrors: false,
concatenateModules: false,
namedModules: false,
hashedModuleIds: false,
minimizer: [uglifyJsForTesting]
};

View File

@ -0,0 +1 @@
module.exports = module.id;

View File

@ -0,0 +1 @@
module.exports = module.id;

View File

@ -0,0 +1 @@
module.exports = module.id;

View File

@ -0,0 +1 @@
module.exports = module.id;

View File

@ -0,0 +1 @@
module.exports = module.id;

View File

@ -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)).not.toBe(expectedModuleId);
}
});

View File

@ -0,0 +1,5 @@
module.exports = {
optimization: {
hashedModuleIds: true
}
};

View File

@ -0,0 +1 @@
module.exports = module.id;

View File

@ -0,0 +1 @@
module.exports = module.id;

View File

@ -0,0 +1 @@
module.exports = module.id;

View File

@ -0,0 +1 @@
module.exports = module.id;

View File

@ -0,0 +1 @@
module.exports = module.id;

View File

@ -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);
}
});

View File

@ -0,0 +1,5 @@
module.exports = {
optimization: {
namedModules: true
}
};