Skip to content

Commit 37b421d

Browse files
authored
Merge pull request webpack#5994 from webpack/feature/mode
add mode option
2 parents 09cc922 + e8f381d commit 37b421d

File tree

194 files changed

+1246
-788
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+1246
-788
lines changed

bin/config-yargs.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ module.exports = function(yargs) {
3030
describe: "Environment passed to the config, when it is a function",
3131
group: CONFIG_GROUP
3232
},
33+
"mode": {
34+
type: "string",
35+
describe: "Mode to use (production or development)",
36+
group: CONFIG_GROUP,
37+
requiresArg: true
38+
},
3339
"context": {
3440
type: "string",
3541
describe: "The root directory for resolving entry point and stats",

bin/convert-argv.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@ module.exports = function(yargs, argv, convertOptions) {
1515
if(!argv.devtool) {
1616
argv.devtool = "eval-cheap-module-source-map";
1717
}
18+
if(!argv.mode) {
19+
argv.mode = "development";
20+
}
1821
}
1922
if(argv.p) {
2023
argv["optimize-minimize"] = true;
2124
argv["define"] = [].concat(argv["define"] || []).concat("process.env.NODE_ENV=\"production\"");
25+
if(!argv.mode) {
26+
argv.mode = "production";
27+
}
2228
}
2329

2430
var configFileLoaded = false;
@@ -288,6 +294,10 @@ module.exports = function(yargs, argv, convertOptions) {
288294
options.plugins.unshift(plugin);
289295
}
290296

297+
ifArg("mode", function(value) {
298+
options.mode = value;
299+
});
300+
291301
ifArgPair("entry", function(name, entry) {
292302
if(typeof options.entry[name] !== "undefined" && options.entry[name] !== null) {
293303
options.entry[name] = [].concat(options.entry[name]).concat(entry);

examples/aggressive-merging/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var path = require("path");
22
var AggressiveMergingPlugin = require("../../lib/optimize/AggressiveMergingPlugin");
33
module.exports = {
4+
mode: "production",
45
entry: {
56
pageA: "./pageA",
67
pageB: "./pageB",

examples/build-common.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ const fs = require("fs");
1111

1212
const extraArgs = "";
1313

14-
const targetArgs = global.NO_TARGET_ARGS ? "" : " ./example.js js/output.js";
14+
const hasConfiguration = fs.existsSync("webpack.config.js");
15+
const targetArgs = global.NO_TARGET_ARGS ? "" : " ./example.js js/output.js ";
1516
const displayReasons = global.NO_REASONS ? "" : " --display-reasons --display-used-exports --display-provided-exports";
16-
cp.exec(`node ${path.resolve(__dirname, "../bin/webpack.js")} ${displayReasons} --display-chunks --display-max-modules 99999 --display-origins --display-entrypoints --output-public-path "js/" -p ${extraArgs} ${targetArgs}`, function(error, stdout, stderr) {
17+
const modeArgs = hasConfiguration ? "" : "--mode production";
18+
cp.exec(`node ${path.resolve(__dirname, "../bin/webpack.js")} ${modeArgs} ${displayReasons} --display-chunks --display-max-modules 99999 --display-origins --display-entrypoints --output-public-path "js/" -p ${extraArgs} ${targetArgs}`, function(error, stdout, stderr) {
1719
if(stderr)
1820
console.log(stderr);
1921
if(error !== null)
@@ -25,7 +27,7 @@ cp.exec(`node ${path.resolve(__dirname, "../bin/webpack.js")} ${displayReasons}
2527
console.log(stderr);
2628
throw e;
2729
}
28-
cp.exec(`node ${path.resolve(__dirname, "../bin/webpack.js")} ${displayReasons} --display-chunks --display-max-modules 99999 --display-origins --display-entrypoints --output-public-path "js/" --output-pathinfo ${extraArgs} ${targetArgs}`, function(error, stdout, stderr) {
30+
cp.exec(`node ${path.resolve(__dirname, "../bin/webpack.js")} ${modeArgs} ${displayReasons} --display-chunks --display-max-modules 99999 --display-origins --display-entrypoints --output-public-path "js/" --output-pathinfo ${extraArgs} ${targetArgs}`, function(error, stdout, stderr) {
2931
console.log(stdout);
3032
if(stderr)
3133
console.log(stderr);

examples/chunkhash/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var path = require("path");
22
var webpack = require("../../");
33
module.exports = {
4+
mode: "production",
45
entry: {
56
main: "./example",
67
common: ["./vendor"] // optional

examples/code-splitted-css-bundle/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const LoaderOptionsPlugin = require("../../lib/LoaderOptionsPlugin");
22
const ExtractTextPlugin = require("extract-text-webpack-plugin");
33
module.exports = {
4+
mode: "production",
45
module: {
56
rules: [
67
{

examples/coffee-script/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
2+
mode: "production",
23
module: {
34
rules: [
45
{ test: /\.coffee$/, loader: "coffee-loader" }

examples/common-chunk-and-vendor-chunk/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var path = require("path");
22
var CommonsChunkPlugin = require("../../lib/optimize/CommonsChunkPlugin");
33

44
module.exports = {
5+
mode: "production",
56
entry: {
67
vendor: ["./vendor1", "./vendor2"],
78
pageA: "./pageA",

examples/common-chunk-grandchildren/webpack.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const path = require("path");
44

55
module.exports = [
66
{
7+
mode: "production",
78
entry: {
89
main: ["./example.js"]
910
},
@@ -21,6 +22,7 @@ module.exports = [
2122
]
2223
},
2324
{
25+
mode: "production",
2426
entry: {
2527
main: ["./example.js"]
2628
},

examples/css-bundle/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const LoaderOptionsPlugin = require("../../lib/LoaderOptionsPlugin");
22
const ExtractTextPlugin = require("extract-text-webpack-plugin");
33
module.exports = {
4+
mode: "production",
45
module: {
56
rules: [
67
{

0 commit comments

Comments
 (0)