add production-expert mode
This commit is contained in:
parent
6922a5e386
commit
c37f1bd16c
|
@ -13,7 +13,11 @@ module.exports = class NoModeWarning extends WebpackError {
|
|||
this.name = "NoModeWarning";
|
||||
this.message = "configuration\n" +
|
||||
"The 'mode' option has not been set. " +
|
||||
"Set 'mode' option to 'development' or 'production' to enable defaults for this enviroment. ";
|
||||
"Set 'mode' option to a vakze to enable defaults for this enviroment. These are your options:\n" +
|
||||
"* \"development\": Use this for development. It enables simple devtools and offers fast incremental compilation with support for watching.\n" +
|
||||
"* \"production\": Use this for a simple production-ready build. It enables optimization for minimal bundle size, but keeps bundle filename constant. It's optimized for a single build without watching.\n" +
|
||||
"* \"production-expert\": This mode enables additional optimizations, which require changing the bundle filename. This makes this mode more difficult to use.\"" +
|
||||
"For further customization possiblilities take a look on the following options: \"devtool\", \"optimizations\", \"output.filename\"";
|
||||
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ const OptionsDefaulter = require("./OptionsDefaulter");
|
|||
const Template = require("./Template");
|
||||
|
||||
const isProductionLikeMode = options => {
|
||||
return options.mode === "production" || !options.mode;
|
||||
return options.mode === "production" || options.mode === "production-expert" || !options.mode;
|
||||
};
|
||||
|
||||
class WebpackOptionsDefaulter extends OptionsDefaulter {
|
||||
|
@ -71,17 +71,19 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
|
|||
}
|
||||
});
|
||||
|
||||
this.set("output.filename", "[name].js");
|
||||
this.set("output.filename", "make", options => options.mode === "production-expert" ? "[chunkhash].js" : "[name].js");
|
||||
this.set("output.chunkFilename", "make", options => {
|
||||
const filename = options.output.filename;
|
||||
const hasName = filename.indexOf("[name]") >= 0;
|
||||
const hasChunkHash = filename.indexOf("[chunkhash]") >= 0;
|
||||
// Anything with [chunkhash] is already fine
|
||||
if(hasChunkHash) return filename;
|
||||
// in production use [chunkhash]
|
||||
if(isProductionLikeMode(options)) return filename.replace(/(^|\/)([^/]*)(\?|$)/, "$1[chunkhash].js");
|
||||
// Replace [name] with [id] because it doesn't require a name map
|
||||
if(hasName) return filename.replace("[name]", "[id]");
|
||||
// Prefix "[id]." in front of the basename
|
||||
return filename.replace(/(^|\/)([^/]*(?:\?|$))/, "$1[id].$2");
|
||||
return filename.replace(/(^|\/)([^/]*)(\?|$)/, "$1[id].$2$3");
|
||||
});
|
||||
this.set("output.webassemblyModuleFilename", "[modulehash].module.wasm");
|
||||
this.set("output.library", "");
|
||||
|
|
|
@ -1121,6 +1121,7 @@
|
|||
"enum": [
|
||||
"development",
|
||||
"production",
|
||||
"production-expert",
|
||||
"none"
|
||||
]
|
||||
},
|
||||
|
|
|
@ -106,8 +106,9 @@ describe("Errors", () => {
|
|||
let lines = warnings[0].split("\n");
|
||||
lines[0].should.match(/configuration/);
|
||||
lines[1].should.match(/mode/);
|
||||
lines[1].should.match(/development/);
|
||||
lines[1].should.match(/production/);
|
||||
lines[2].should.match(/development/);
|
||||
lines[3].should.match(/production/);
|
||||
lines[4].should.match(/production-expert/);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue