Merge pull request #5359 from esbenp/cli-prepend-plugins-4260

prepend plugins instead of append when defined through CLI
This commit is contained in:
Tobias Koppers 2017-09-14 09:24:10 +02:00 committed by GitHub
commit 1ff24a7bab
6 changed files with 46 additions and 19 deletions

View File

@ -283,6 +283,11 @@ module.exports = function(yargs, argv, convertOptions) {
}
}
function addPlugin(options, plugin) {
ensureArray(options, "plugins");
options.plugins.unshift(plugin);
}
ifArgPair("entry", function(name, entry) {
if(typeof options.entry[name] !== "undefined" && options.entry[name] !== null) {
options.entry[name] = [].concat(options.entry[name]).concat(entry);
@ -328,9 +333,8 @@ module.exports = function(yargs, argv, convertOptions) {
}, function() {
defineObject = {};
}, function() {
ensureArray(options, "plugins");
var DefinePlugin = require("../lib/DefinePlugin");
options.plugins.push(new DefinePlugin(defineObject));
addPlugin(options, new DefinePlugin(defineObject));
});
ifArg("output-path", function(value) {
@ -398,15 +402,13 @@ module.exports = function(yargs, argv, convertOptions) {
mapArgToBoolean("cache");
ifBooleanArg("hot", function() {
ensureArray(options, "plugins");
var HotModuleReplacementPlugin = require("../lib/HotModuleReplacementPlugin");
options.plugins.push(new HotModuleReplacementPlugin());
addPlugin(options, new HotModuleReplacementPlugin());
});
ifBooleanArg("debug", function() {
ensureArray(options, "plugins");
var LoaderOptionsPlugin = require("../lib/LoaderOptionsPlugin");
options.plugins.push(new LoaderOptionsPlugin({
addPlugin(options, new LoaderOptionsPlugin({
debug: true
}));
});
@ -438,41 +440,36 @@ module.exports = function(yargs, argv, convertOptions) {
});
ifArg("optimize-max-chunks", function(value) {
ensureArray(options, "plugins");
var LimitChunkCountPlugin = require("../lib/optimize/LimitChunkCountPlugin");
options.plugins.push(new LimitChunkCountPlugin({
addPlugin(options, new LimitChunkCountPlugin({
maxChunks: parseInt(value, 10)
}));
});
ifArg("optimize-min-chunk-size", function(value) {
ensureArray(options, "plugins");
var MinChunkSizePlugin = require("../lib/optimize/MinChunkSizePlugin");
options.plugins.push(new MinChunkSizePlugin({
addPlugin(options, new MinChunkSizePlugin({
minChunkSize: parseInt(value, 10)
}));
});
ifBooleanArg("optimize-minimize", function() {
ensureArray(options, "plugins");
var UglifyJsPlugin = require("../lib/optimize/UglifyJsPlugin");
var LoaderOptionsPlugin = require("../lib/LoaderOptionsPlugin");
options.plugins.push(new UglifyJsPlugin({
addPlugin(options, new UglifyJsPlugin({
sourceMap: options.devtool && (options.devtool.indexOf("sourcemap") >= 0 || options.devtool.indexOf("source-map") >= 0)
}));
options.plugins.push(new LoaderOptionsPlugin({
addPlugin(options, new LoaderOptionsPlugin({
minimize: true
}));
});
ifArg("prefetch", function(request) {
ensureArray(options, "plugins");
var PrefetchPlugin = require("../lib/PrefetchPlugin");
options.plugins.push(new PrefetchPlugin(request));
addPlugin(options, new PrefetchPlugin(request));
});
ifArg("provide", function(value) {
ensureArray(options, "plugins");
var idx = value.indexOf("=");
var name;
if(idx >= 0) {
@ -482,12 +479,11 @@ module.exports = function(yargs, argv, convertOptions) {
name = value;
}
var ProvidePlugin = require("../lib/ProvidePlugin");
options.plugins.push(new ProvidePlugin(name, value));
addPlugin(options, new ProvidePlugin(name, value));
});
ifArg("plugin", function(value) {
ensureArray(options, "plugins");
options.plugins.push(loadPlugin(value));
addPlugin(options, loadPlugin(value));
});
mapArgToBoolean("bail");

View File

@ -0,0 +1,4 @@
// We test that the CLI define for TEST will override the one defined in
// webpack.config.js. If the presedence is correct the entry will require ok.js,
// if not it will try to require fail.js and fail.
require("./" + TEST + ".js");

View File

@ -0,0 +1 @@
module.exports = "ok";

View File

@ -0,0 +1,9 @@
"use strict";
module.exports = function testAssertions(code, stdout, stderr) {
code.should.be.exactly(0);
stdout.should.be.ok();
stdout[6].should.containEql("ok.js");
stderr.should.be.empty();
};

View File

@ -0,0 +1,6 @@
--entry ./index.js
--config ./webpack.config.js
--output-filename [name].js
--output-chunk-filename [id].chunk.js
--target async-node
--define TEST="ok"

View File

@ -0,0 +1,11 @@
var DefinePlugin = require("../../../../lib/DefinePlugin");
var path = require("path");
module.exports = {
entry: path.resolve(__dirname, "./index"),
plugins: [
new DefinePlugin({
TEST: JSON.stringify("fail")
})
]
};