mirror of https://github.com/webpack/webpack.git
validate compiler options in multicompiler mode
This commit is contained in:
parent
bb0fdc9191
commit
076bc4af7f
|
@ -11,6 +11,7 @@ const { SyncHook, MultiHook } = require("tapable");
|
||||||
const ConcurrentCompilationError = require("./ConcurrentCompilationError");
|
const ConcurrentCompilationError = require("./ConcurrentCompilationError");
|
||||||
const MultiStats = require("./MultiStats");
|
const MultiStats = require("./MultiStats");
|
||||||
const MultiWatching = require("./MultiWatching");
|
const MultiWatching = require("./MultiWatching");
|
||||||
|
const WebpackError = require("./WebpackError");
|
||||||
const ArrayQueue = require("./util/ArrayQueue");
|
const ArrayQueue = require("./util/ArrayQueue");
|
||||||
|
|
||||||
/** @template T @typedef {import("tapable").AsyncSeriesHook<T>} AsyncSeriesHook<T> */
|
/** @template T @typedef {import("tapable").AsyncSeriesHook<T>} AsyncSeriesHook<T> */
|
||||||
|
@ -104,6 +105,34 @@ module.exports = class MultiCompiler {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
this._validateCompilersOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
_validateCompilersOptions() {
|
||||||
|
if (this.compilers.length < 2) return;
|
||||||
|
const cacheNames = new Set();
|
||||||
|
const addWarning = (compiler, warning) => {
|
||||||
|
compiler.hooks.thisCompilation.tap("MultiCompiler", compilation => {
|
||||||
|
compilation.warnings.push(warning);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
for (const compiler of this.compilers) {
|
||||||
|
if (compiler.options.cache && "name" in compiler.options.cache) {
|
||||||
|
const cacheName = compiler.options.cache && compiler.options.cache.name;
|
||||||
|
if (cacheNames.has(cacheName)) {
|
||||||
|
addWarning(
|
||||||
|
compiler,
|
||||||
|
new WebpackError(
|
||||||
|
`Compiler cache with name ${JSON.stringify(
|
||||||
|
cacheName
|
||||||
|
)} is already defined. Please set unique "cache.name" option.`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
cacheNames.add(cacheName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get options() {
|
get options() {
|
||||||
|
|
|
@ -78,6 +78,17 @@ describe("StatsTestCases", () => {
|
||||||
if (!options.optimization) options.optimization = {};
|
if (!options.optimization) options.optimization = {};
|
||||||
if (options.optimization.minimize === undefined)
|
if (options.optimization.minimize === undefined)
|
||||||
options.optimization.minimize = false;
|
options.optimization.minimize = false;
|
||||||
|
if (
|
||||||
|
options.cache &&
|
||||||
|
options.cache !== true &&
|
||||||
|
options.cache.type === "filesystem"
|
||||||
|
) {
|
||||||
|
options.cache.cacheLocation = path.resolve(
|
||||||
|
outputBase,
|
||||||
|
".cache",
|
||||||
|
testName
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
const c = webpack(options);
|
const c = webpack(options);
|
||||||
const compilers = c.compilers ? c.compilers : [c];
|
const compilers = c.compilers ? c.compilers : [c];
|
||||||
|
|
|
@ -1620,6 +1620,19 @@ You may need an appropriate loader to handle this file type, currently no loader
|
||||||
webpack x.x.x compiled with 2 errors in X ms"
|
webpack x.x.x compiled with 2 errors in X ms"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`StatsTestCases should print correct stats for multicompiler-mode-cache 1`] = `
|
||||||
|
"1 asset
|
||||||
|
1 module
|
||||||
|
webpack x.x.x compiled successfully in X ms
|
||||||
|
|
||||||
|
1 asset
|
||||||
|
1 module
|
||||||
|
|
||||||
|
WARNING in Compiler cache with name \\"name1\\" is already defined. Please set unique \\"cache.name\\" option.
|
||||||
|
|
||||||
|
webpack x.x.x compiled with 1 warning in X ms"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`StatsTestCases should print correct stats for named-chunk-groups 1`] = `
|
exports[`StatsTestCases should print correct stats for named-chunk-groups 1`] = `
|
||||||
"Chunk Group main 11.7 KiB = a-main.js
|
"Chunk Group main 11.7 KiB = a-main.js
|
||||||
Chunk Group async-a 1.07 KiB = a-52.js 257 bytes a-async-a.js 836 bytes
|
Chunk Group async-a 1.07 KiB = a-52.js 257 bytes a-async-a.js 836 bytes
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/** @type {import("../../../").Configuration} */
|
||||||
|
module.exports = [
|
||||||
|
{
|
||||||
|
mode: "production",
|
||||||
|
entry: "./index",
|
||||||
|
cache: {
|
||||||
|
type: "filesystem",
|
||||||
|
name: "name1"
|
||||||
|
},
|
||||||
|
stats: { preset: "minimal" }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
mode: "production",
|
||||||
|
entry: "./index",
|
||||||
|
cache: {
|
||||||
|
type: "filesystem",
|
||||||
|
name: "name1"
|
||||||
|
},
|
||||||
|
stats: { preset: "minimal" }
|
||||||
|
}
|
||||||
|
];
|
Loading…
Reference in New Issue