mirror of https://github.com/webpack/webpack.git
refactor: code
This commit is contained in:
parent
171bae7912
commit
8a04c64e5e
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Arka Pratim Chaudhuri @arkapratimc
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
|
||||
class FalseIIFEUmdWarning extends WebpackError {
|
||||
constructor() {
|
||||
super();
|
||||
this.name = "FalseIIFEUmdWarning";
|
||||
this.message =
|
||||
"Configuration:\nSetting 'output.iife' to 'false' is incompatible with 'output.library.type' set to 'umd'. This configuration may cause unexpected behavior, as UMD libraries are expected to use an IIFE (Immediately Invoked Function Expression) to support various module formats. Consider setting 'output.iife' to 'true' or choosing a different 'library.type' to ensure compatibility.\nLearn more: https://webpack.js.org/configuration/output/";
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FalseIIFEUmdWarning;
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Arka Pratim Chaudhuri @arkapratimc
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const WebpackError = require("./WebpackError");
|
||||
|
||||
class FalseIifeUmdWarning extends WebpackError {
|
||||
constructor() {
|
||||
super();
|
||||
this.name = "FalseIifeUmdWarning";
|
||||
this.message =
|
||||
"configuration\n" +
|
||||
"Setting 'output.iife' to 'false' is incompatible with 'output.library.type' set to 'umd'. This configuration may cause unexpected behavior, as UMD libraries are expected to use an IIFE (Immediately Invoked Function Expression) to support various module formats. Consider setting 'output.iife' to 'true' or choosing a different 'library.type' to ensure compatibility.\nLearn more: https://webpack.js.org/configuration/output/";
|
||||
}
|
||||
}
|
||||
|
||||
class WarnFalseIifeUmdPlugin {
|
||||
apply(compiler) {
|
||||
compiler.hooks.thisCompilation.tap(
|
||||
"WarnFalseIifeUmdPlugin",
|
||||
compilation => {
|
||||
compilation.warnings.push(new FalseIifeUmdWarning());
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WarnFalseIifeUmdPlugin;
|
|
@ -209,15 +209,6 @@ class WebpackOptionsApply extends OptionsApply {
|
|||
}
|
||||
}
|
||||
|
||||
if (
|
||||
options.output.iife === false &&
|
||||
options.output.library &&
|
||||
options.output.library.type === "umd"
|
||||
) {
|
||||
const WarnFalseIifeUmdPlugin = require("./WarnFalseIifeUmdPlugin");
|
||||
new WarnFalseIifeUmdPlugin().apply(compiler);
|
||||
}
|
||||
|
||||
const enabledChunkLoadingTypes =
|
||||
/** @type {NonNullable<WebpackOptions["output"]["enabledChunkLoadingTypes"]>} */
|
||||
(options.output.enabledChunkLoadingTypes);
|
||||
|
|
|
@ -748,10 +748,7 @@ class JavascriptModulesPlugin {
|
|||
const { chunk, chunkGraph, runtimeTemplate } = renderContext;
|
||||
|
||||
const runtimeRequirements = chunkGraph.getTreeRuntimeRequirements(chunk);
|
||||
const iife =
|
||||
runtimeTemplate.isIIFE() ||
|
||||
(runtimeTemplate.outputOptions.library &&
|
||||
runtimeTemplate.outputOptions.library.type === "umd");
|
||||
const iife = runtimeTemplate.isIIFE();
|
||||
|
||||
const bootstrap = this.renderBootstrap(renderContext, hooks);
|
||||
const useSourceMap = hooks.useSourceMap.call(chunk, renderContext);
|
||||
|
|
|
@ -208,6 +208,23 @@ class EnableLibraryPlugin {
|
|||
}
|
||||
case "umd":
|
||||
case "umd2": {
|
||||
if (compiler.options.output.iife === false) {
|
||||
compiler.options.output.iife = true;
|
||||
|
||||
class WarnFalseIifeUmdPlugin {
|
||||
apply(compiler) {
|
||||
compiler.hooks.thisCompilation.tap(
|
||||
"WarnFalseIifeUmdPlugin",
|
||||
compilation => {
|
||||
const FalseIIFEUmdWarning = require("../FalseIIFEUmdWarning");
|
||||
compilation.warnings.push(new FalseIIFEUmdWarning());
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
new WarnFalseIifeUmdPlugin().apply(compiler);
|
||||
}
|
||||
enableExportProperty();
|
||||
const UmdLibraryPlugin = require("./UmdLibraryPlugin");
|
||||
new UmdLibraryPlugin({
|
||||
|
|
|
@ -385,8 +385,8 @@ it("should emit warning when 'output.iife'=false is used with 'output.library.ty
|
|||
"errors": Array [],
|
||||
"warnings": Array [
|
||||
Object {
|
||||
"message": "configuration\\nSetting 'output.iife' to 'false' is incompatible with 'output.library.type' set to 'umd'. This configuration may cause unexpected behavior, as UMD libraries are expected to use an IIFE (Immediately Invoked Function Expression) to support various module formats. Consider setting 'output.iife' to 'true' or choosing a different 'library.type' to ensure compatibility.\\nLearn more: https://webpack.js.org/configuration/output/",
|
||||
"stack": "FalseIifeUmdWarning: configuration\\nSetting 'output.iife' to 'false' is incompatible with 'output.library.type' set to 'umd'. This configuration may cause unexpected behavior, as UMD libraries are expected to use an IIFE (Immediately Invoked Function Expression) to support various module formats. Consider setting 'output.iife' to 'true' or choosing a different 'library.type' to ensure compatibility.\\nLearn more: https://webpack.js.org/configuration/output/",
|
||||
"message": "Configuration:\\nSetting 'output.iife' to 'false' is incompatible with 'output.library.type' set to 'umd'. This configuration may cause unexpected behavior, as UMD libraries are expected to use an IIFE (Immediately Invoked Function Expression) to support various module formats. Consider setting 'output.iife' to 'true' or choosing a different 'library.type' to ensure compatibility.\\nLearn more: https://webpack.js.org/configuration/output/",
|
||||
"stack": "FalseIIFEUmdWarning: Configuration:\\nSetting 'output.iife' to 'false' is incompatible with 'output.library.type' set to 'umd'. This configuration may cause unexpected behavior, as UMD libraries are expected to use an IIFE (Immediately Invoked Function Expression) to support various module formats. Consider setting 'output.iife' to 'true' or choosing a different 'library.type' to ensure compatibility.\\nLearn more: https://webpack.js.org/configuration/output/",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
@ -153,22 +153,6 @@ module.exports = (env, { testPath }) => [
|
|||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
output: {
|
||||
uniqueName: "false-iife-umd",
|
||||
filename: "false-iife-umd.js",
|
||||
library: {
|
||||
type: "umd"
|
||||
},
|
||||
iife: false
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
external: "./non-external"
|
||||
}
|
||||
},
|
||||
ignoreWarnings: [error => error.name === "FalseIifeUmdWarning"]
|
||||
},
|
||||
{
|
||||
output: {
|
||||
uniqueName: "true-iife-umd",
|
||||
|
@ -184,6 +168,38 @@ module.exports = (env, { testPath }) => [
|
|||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
output: {
|
||||
uniqueName: "false-iife-umd",
|
||||
filename: "false-iife-umd.js",
|
||||
library: {
|
||||
type: "umd"
|
||||
},
|
||||
iife: false
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
external: "./non-external"
|
||||
}
|
||||
},
|
||||
ignoreWarnings: [error => error.name === "FalseIIFEUmdWarning"]
|
||||
},
|
||||
{
|
||||
output: {
|
||||
uniqueName: "false-iife-umd2",
|
||||
filename: "false-iife-umd2.js",
|
||||
library: {
|
||||
type: "umd2"
|
||||
},
|
||||
iife: false
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
external: "./non-external"
|
||||
}
|
||||
},
|
||||
ignoreWarnings: [error => error.name === "FalseIIFEUmdWarning"]
|
||||
},
|
||||
{
|
||||
output: {
|
||||
uniqueName: "umd-default",
|
||||
|
|
|
@ -165,6 +165,18 @@ module.exports = (env, { testPath }) => [
|
|||
})
|
||||
]
|
||||
},
|
||||
{
|
||||
resolve: {
|
||||
alias: {
|
||||
library: path.resolve(testPath, "../0-create-library/true-iife-umd.js")
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
NAME: JSON.stringify("true-iife-umd")
|
||||
})
|
||||
]
|
||||
},
|
||||
{
|
||||
resolve: {
|
||||
alias: {
|
||||
|
@ -180,12 +192,15 @@ module.exports = (env, { testPath }) => [
|
|||
{
|
||||
resolve: {
|
||||
alias: {
|
||||
library: path.resolve(testPath, "../0-create-library/true-iife-umd.js")
|
||||
library: path.resolve(
|
||||
testPath,
|
||||
"../0-create-library/false-iife-umd2.js"
|
||||
)
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
NAME: JSON.stringify("true-iife-umd")
|
||||
NAME: JSON.stringify("false-iife-umd2")
|
||||
})
|
||||
]
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue