Merge pull request #11258 from gkjohnson/dynamically-resolve-public-path
Dynamically resolve public path by default
This commit is contained in:
commit
f502828e99
|
@ -466,6 +466,10 @@ export type Iife = boolean;
|
||||||
* The name of the native import() function (can be exchanged for a polyfill).
|
* The name of the native import() function (can be exchanged for a polyfill).
|
||||||
*/
|
*/
|
||||||
export type ImportFunctionName = string;
|
export type ImportFunctionName = string;
|
||||||
|
/**
|
||||||
|
* The name of the native import.meta object (can be exchanged for a polyfill).
|
||||||
|
*/
|
||||||
|
export type ImportMetaName = string;
|
||||||
/**
|
/**
|
||||||
* Make the output files a library, exporting the exports of the entry point.
|
* Make the output files a library, exporting the exports of the entry point.
|
||||||
*/
|
*/
|
||||||
|
@ -486,6 +490,7 @@ export type Pathinfo = boolean;
|
||||||
* The `publicPath` specifies the public URL address of the output files when referenced in a browser.
|
* The `publicPath` specifies the public URL address of the output files when referenced in a browser.
|
||||||
*/
|
*/
|
||||||
export type PublicPath =
|
export type PublicPath =
|
||||||
|
| "auto"
|
||||||
| string
|
| string
|
||||||
| ((
|
| ((
|
||||||
pathData: import("../lib/Compilation").PathData,
|
pathData: import("../lib/Compilation").PathData,
|
||||||
|
@ -1759,6 +1764,10 @@ export interface Output {
|
||||||
* The name of the native import() function (can be exchanged for a polyfill).
|
* The name of the native import() function (can be exchanged for a polyfill).
|
||||||
*/
|
*/
|
||||||
importFunctionName?: ImportFunctionName;
|
importFunctionName?: ImportFunctionName;
|
||||||
|
/**
|
||||||
|
* The name of the native import.meta object (can be exchanged for a polyfill).
|
||||||
|
*/
|
||||||
|
importMetaName?: ImportMetaName;
|
||||||
/**
|
/**
|
||||||
* Make the output files a library, exporting the exports of the entry point.
|
* Make the output files a library, exporting the exports of the entry point.
|
||||||
*/
|
*/
|
||||||
|
@ -2426,6 +2435,10 @@ export interface OutputNormalized {
|
||||||
* The name of the native import() function (can be exchanged for a polyfill).
|
* The name of the native import() function (can be exchanged for a polyfill).
|
||||||
*/
|
*/
|
||||||
importFunctionName?: ImportFunctionName;
|
importFunctionName?: ImportFunctionName;
|
||||||
|
/**
|
||||||
|
* The name of the native import.meta object (can be exchanged for a polyfill).
|
||||||
|
*/
|
||||||
|
importMetaName?: ImportMetaName;
|
||||||
/**
|
/**
|
||||||
* Options for library.
|
* Options for library.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
const RuntimeGlobals = require("./RuntimeGlobals");
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
||||||
const RuntimeRequirementsDependency = require("./dependencies/RuntimeRequirementsDependency");
|
const RuntimeRequirementsDependency = require("./dependencies/RuntimeRequirementsDependency");
|
||||||
const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
|
const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
|
||||||
|
const AutoPublicPathRuntimeModule = require("./runtime/AutoPublicPathRuntimeModule");
|
||||||
const CompatGetDefaultExportRuntimeModule = require("./runtime/CompatGetDefaultExportRuntimeModule");
|
const CompatGetDefaultExportRuntimeModule = require("./runtime/CompatGetDefaultExportRuntimeModule");
|
||||||
const CompatRuntimeModule = require("./runtime/CompatRuntimeModule");
|
const CompatRuntimeModule = require("./runtime/CompatRuntimeModule");
|
||||||
const CreateFakeNamespaceObjectRuntimeModule = require("./runtime/CreateFakeNamespaceObjectRuntimeModule");
|
const CreateFakeNamespaceObjectRuntimeModule = require("./runtime/CreateFakeNamespaceObjectRuntimeModule");
|
||||||
|
@ -157,16 +158,26 @@ class RuntimePlugin {
|
||||||
});
|
});
|
||||||
compilation.hooks.runtimeRequirementInTree
|
compilation.hooks.runtimeRequirementInTree
|
||||||
.for(RuntimeGlobals.publicPath)
|
.for(RuntimeGlobals.publicPath)
|
||||||
.tap("RuntimePlugin", chunk => {
|
.tap("RuntimePlugin", (chunk, set) => {
|
||||||
const module = new PublicPathRuntimeModule();
|
const { outputOptions } = compilation;
|
||||||
const publicPath = compilation.outputOptions.publicPath;
|
const { publicPath, scriptType } = outputOptions;
|
||||||
if (
|
|
||||||
typeof publicPath !== "string" ||
|
if (publicPath === "auto") {
|
||||||
/\[(full)?hash\]/.test(publicPath)
|
const module = new AutoPublicPathRuntimeModule();
|
||||||
) {
|
if (scriptType !== "module") set.add(RuntimeGlobals.global);
|
||||||
module.fullHash = true;
|
compilation.addRuntimeModule(chunk, module);
|
||||||
|
} else {
|
||||||
|
const module = new PublicPathRuntimeModule();
|
||||||
|
|
||||||
|
if (
|
||||||
|
typeof publicPath !== "string" ||
|
||||||
|
/\[(full)?hash\]/.test(publicPath)
|
||||||
|
) {
|
||||||
|
module.fullHash = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
compilation.addRuntimeModule(chunk, module);
|
||||||
}
|
}
|
||||||
compilation.addRuntimeModule(chunk, module);
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
compilation.hooks.runtimeRequirementInTree
|
compilation.hooks.runtimeRequirementInTree
|
||||||
|
|
|
@ -91,6 +91,11 @@ class RuntimeTemplate {
|
||||||
return this.outputOptions.environment.module;
|
return this.outputOptions.environment.module;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
supportTemplateLiteral() {
|
||||||
|
// TODO
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
returningFunction(returnValue, args = "") {
|
returningFunction(returnValue, args = "") {
|
||||||
return this.supportsArrowFunction()
|
return this.supportsArrowFunction()
|
||||||
? `(${args}) => ${returnValue}`
|
? `(${args}) => ${returnValue}`
|
||||||
|
|
|
@ -537,6 +537,7 @@ const applyOutputDefaults = (
|
||||||
F(output, "module", () => !!outputModule);
|
F(output, "module", () => !!outputModule);
|
||||||
F(output, "iife", () => !output.module);
|
F(output, "iife", () => !output.module);
|
||||||
D(output, "importFunctionName", "import");
|
D(output, "importFunctionName", "import");
|
||||||
|
D(output, "importMetaName", "import.meta");
|
||||||
F(output, "chunkFilename", () => {
|
F(output, "chunkFilename", () => {
|
||||||
const filename = output.filename;
|
const filename = output.filename;
|
||||||
if (typeof filename !== "function") {
|
if (typeof filename !== "function") {
|
||||||
|
@ -553,7 +554,6 @@ const applyOutputDefaults = (
|
||||||
});
|
});
|
||||||
D(output, "assetModuleFilename", "[hash][ext][query]");
|
D(output, "assetModuleFilename", "[hash][ext][query]");
|
||||||
D(output, "webassemblyModuleFilename", "[hash].module.wasm");
|
D(output, "webassemblyModuleFilename", "[hash].module.wasm");
|
||||||
D(output, "publicPath", "");
|
|
||||||
D(output, "compareBeforeEmit", true);
|
D(output, "compareBeforeEmit", true);
|
||||||
D(output, "charset", true);
|
D(output, "charset", true);
|
||||||
F(output, "hotUpdateGlobal", () =>
|
F(output, "hotUpdateGlobal", () =>
|
||||||
|
@ -639,6 +639,13 @@ const applyOutputDefaults = (
|
||||||
D(output, "hotUpdateMainFilename", "[fullhash].hot-update.json");
|
D(output, "hotUpdateMainFilename", "[fullhash].hot-update.json");
|
||||||
D(output, "crossOriginLoading", false);
|
D(output, "crossOriginLoading", false);
|
||||||
F(output, "scriptType", () => (output.module ? "module" : false));
|
F(output, "scriptType", () => (output.module ? "module" : false));
|
||||||
|
D(
|
||||||
|
output,
|
||||||
|
"publicPath",
|
||||||
|
(tp && (tp.document || tp.importScripts)) || output.scriptType === "module"
|
||||||
|
? "auto"
|
||||||
|
: ""
|
||||||
|
);
|
||||||
D(output, "chunkLoadTimeout", 120000);
|
D(output, "chunkLoadTimeout", 120000);
|
||||||
D(output, "hashFunction", "md4");
|
D(output, "hashFunction", "md4");
|
||||||
D(output, "hashDigest", "hex");
|
D(output, "hashDigest", "hex");
|
||||||
|
|
|
@ -252,6 +252,7 @@ const getNormalizedWebpackOptions = config => {
|
||||||
hotUpdateMainFilename: output.hotUpdateMainFilename,
|
hotUpdateMainFilename: output.hotUpdateMainFilename,
|
||||||
iife: output.iife,
|
iife: output.iife,
|
||||||
importFunctionName: output.importFunctionName,
|
importFunctionName: output.importFunctionName,
|
||||||
|
importMetaName: output.importMetaName,
|
||||||
scriptType: output.scriptType,
|
scriptType: output.scriptType,
|
||||||
library: libraryBase && {
|
library: libraryBase && {
|
||||||
type:
|
type:
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
||||||
|
const RuntimeModule = require("../RuntimeModule");
|
||||||
|
const Template = require("../Template");
|
||||||
|
const JavascriptModulesPlugin = require("../javascript/JavascriptModulesPlugin");
|
||||||
|
const { getUndoPath } = require("../util/identifier");
|
||||||
|
|
||||||
|
class AutoPublicPathRuntimeModule extends RuntimeModule {
|
||||||
|
constructor() {
|
||||||
|
super("publicPath", 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {string} runtime code
|
||||||
|
*/
|
||||||
|
generate() {
|
||||||
|
const { compilation } = this;
|
||||||
|
const { scriptType, importMetaName } = compilation.outputOptions;
|
||||||
|
const chunkName = compilation.getPath(
|
||||||
|
JavascriptModulesPlugin.getChunkFilenameTemplate(
|
||||||
|
this.chunk,
|
||||||
|
compilation.outputOptions
|
||||||
|
),
|
||||||
|
{
|
||||||
|
chunk: this.chunk,
|
||||||
|
contentHashType: "javascript"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const undoPath = getUndoPath(chunkName, false);
|
||||||
|
return Template.asString([
|
||||||
|
"var scriptUrl;",
|
||||||
|
scriptType === "module"
|
||||||
|
? `if (typeof ${importMetaName}.url === "string") scriptUrl = ${importMetaName}.url`
|
||||||
|
: Template.asString([
|
||||||
|
`if (${RuntimeGlobals.global}.importScripts) scriptUrl = ${RuntimeGlobals.global}.location + "";`,
|
||||||
|
`var document = ${RuntimeGlobals.global}.document;`,
|
||||||
|
"if (!scriptUrl && document) {",
|
||||||
|
Template.indent([
|
||||||
|
`if (document.currentScript)`,
|
||||||
|
Template.indent(`scriptUrl = document.currentScript.src`),
|
||||||
|
"if (!scriptUrl) {",
|
||||||
|
Template.indent([
|
||||||
|
'var scripts = document.getElementsByTagName("script");',
|
||||||
|
"if(scripts.length) scriptUrl = scripts[scripts.length - 1].src"
|
||||||
|
]),
|
||||||
|
"}"
|
||||||
|
]),
|
||||||
|
"}"
|
||||||
|
]),
|
||||||
|
"// When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration",
|
||||||
|
'// or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.',
|
||||||
|
'if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");',
|
||||||
|
'scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\\?.*$/, "").replace(/\\/[^\\/]+$/, "/");',
|
||||||
|
!undoPath
|
||||||
|
? `${RuntimeGlobals.publicPath} = scriptUrl;`
|
||||||
|
: `${RuntimeGlobals.publicPath} = scriptUrl + ${JSON.stringify(
|
||||||
|
undoPath
|
||||||
|
)};`
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = AutoPublicPathRuntimeModule;
|
|
@ -7,24 +7,22 @@
|
||||||
const RuntimeGlobals = require("../RuntimeGlobals");
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
||||||
const RuntimeModule = require("../RuntimeModule");
|
const RuntimeModule = require("../RuntimeModule");
|
||||||
|
|
||||||
/** @typedef {import("../Compilation")} Compilation */
|
|
||||||
|
|
||||||
class PublicPathRuntimeModule extends RuntimeModule {
|
class PublicPathRuntimeModule extends RuntimeModule {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("publicPath");
|
super("publicPath", 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {string} runtime code
|
* @returns {string} runtime code
|
||||||
*/
|
*/
|
||||||
generate() {
|
generate() {
|
||||||
|
const { compilation } = this;
|
||||||
|
const { publicPath } = compilation.outputOptions;
|
||||||
|
|
||||||
return `${RuntimeGlobals.publicPath} = ${JSON.stringify(
|
return `${RuntimeGlobals.publicPath} = ${JSON.stringify(
|
||||||
this.compilation.getPath(
|
this.compilation.getPath(publicPath || "", {
|
||||||
this.compilation.outputOptions.publicPath || "",
|
hash: this.compilation.hash || "XXXX"
|
||||||
{
|
})
|
||||||
hash: this.compilation.hash || "XXXX"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)};`;
|
)};`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -780,6 +780,10 @@
|
||||||
"description": "The name of the native import() function (can be exchanged for a polyfill).",
|
"description": "The name of the native import() function (can be exchanged for a polyfill).",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"ImportMetaName": {
|
||||||
|
"description": "The name of the native import.meta object (can be exchanged for a polyfill).",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"InfrastructureLogging": {
|
"InfrastructureLogging": {
|
||||||
"description": "Options for infrastructure level logging.",
|
"description": "Options for infrastructure level logging.",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
@ -1868,6 +1872,9 @@
|
||||||
"importFunctionName": {
|
"importFunctionName": {
|
||||||
"$ref": "#/definitions/ImportFunctionName"
|
"$ref": "#/definitions/ImportFunctionName"
|
||||||
},
|
},
|
||||||
|
"importMetaName": {
|
||||||
|
"$ref": "#/definitions/ImportMetaName"
|
||||||
|
},
|
||||||
"library": {
|
"library": {
|
||||||
"$ref": "#/definitions/Library"
|
"$ref": "#/definitions/Library"
|
||||||
},
|
},
|
||||||
|
@ -2032,6 +2039,9 @@
|
||||||
"importFunctionName": {
|
"importFunctionName": {
|
||||||
"$ref": "#/definitions/ImportFunctionName"
|
"$ref": "#/definitions/ImportFunctionName"
|
||||||
},
|
},
|
||||||
|
"importMetaName": {
|
||||||
|
"$ref": "#/definitions/ImportMetaName"
|
||||||
|
},
|
||||||
"library": {
|
"library": {
|
||||||
"$ref": "#/definitions/LibraryOptions"
|
"$ref": "#/definitions/LibraryOptions"
|
||||||
},
|
},
|
||||||
|
@ -2147,6 +2157,9 @@
|
||||||
"PublicPath": {
|
"PublicPath": {
|
||||||
"description": "The `publicPath` specifies the public URL address of the output files when referenced in a browser.",
|
"description": "The `publicPath` specifies the public URL address of the output files when referenced in a browser.",
|
||||||
"anyOf": [
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"enum": ["auto"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,6 +9,7 @@ const checkArrayExpectation = require("./checkArrayExpectation");
|
||||||
const createLazyTestEnv = require("./helpers/createLazyTestEnv");
|
const createLazyTestEnv = require("./helpers/createLazyTestEnv");
|
||||||
const deprecationTracking = require("./helpers/deprecationTracking");
|
const deprecationTracking = require("./helpers/deprecationTracking");
|
||||||
const FakeDocument = require("./helpers/FakeDocument");
|
const FakeDocument = require("./helpers/FakeDocument");
|
||||||
|
const CurrentScript = require("./helpers/CurrentScript");
|
||||||
|
|
||||||
const webpack = require("..");
|
const webpack = require("..");
|
||||||
const prepareOptions = require("./helpers/prepareOptions");
|
const prepareOptions = require("./helpers/prepareOptions");
|
||||||
|
@ -222,12 +223,13 @@ const describeCases = config => {
|
||||||
const bundlePath = testConfig.findBundle(i, optionsArr[i]);
|
const bundlePath = testConfig.findBundle(i, optionsArr[i]);
|
||||||
if (bundlePath) {
|
if (bundlePath) {
|
||||||
filesCount++;
|
filesCount++;
|
||||||
|
const document = new FakeDocument();
|
||||||
const globalContext = {
|
const globalContext = {
|
||||||
console: console,
|
console: console,
|
||||||
expect: expect,
|
expect: expect,
|
||||||
setTimeout: setTimeout,
|
setTimeout: setTimeout,
|
||||||
clearTimeout: clearTimeout,
|
clearTimeout: clearTimeout,
|
||||||
document: new FakeDocument(),
|
document,
|
||||||
location: {
|
location: {
|
||||||
href: "https://test.cases/path/index.html",
|
href: "https://test.cases/path/index.html",
|
||||||
origin: "https://test.cases",
|
origin: "https://test.cases",
|
||||||
|
@ -243,6 +245,7 @@ const describeCases = config => {
|
||||||
if (Array.isArray(module) || /^\.\.?\//.test(module)) {
|
if (Array.isArray(module) || /^\.\.?\//.test(module)) {
|
||||||
let content;
|
let content;
|
||||||
let p;
|
let p;
|
||||||
|
let subPath = "";
|
||||||
if (Array.isArray(module)) {
|
if (Array.isArray(module)) {
|
||||||
p = path.join(currentDirectory, ".array-require.js");
|
p = path.join(currentDirectory, ".array-require.js");
|
||||||
content = `module.exports = (${module
|
content = `module.exports = (${module
|
||||||
|
@ -253,6 +256,26 @@ const describeCases = config => {
|
||||||
} else {
|
} else {
|
||||||
p = path.join(currentDirectory, module);
|
p = path.join(currentDirectory, module);
|
||||||
content = fs.readFileSync(p, "utf-8");
|
content = fs.readFileSync(p, "utf-8");
|
||||||
|
const lastSlash = module.lastIndexOf("/");
|
||||||
|
let firstSlash = module.indexOf("/");
|
||||||
|
|
||||||
|
if (lastSlash !== -1 && firstSlash !== lastSlash) {
|
||||||
|
if (firstSlash !== -1) {
|
||||||
|
let next = module.indexOf("/", firstSlash + 1);
|
||||||
|
let dir = module.slice(firstSlash + 1, next);
|
||||||
|
|
||||||
|
while (dir === ".") {
|
||||||
|
firstSlash = next;
|
||||||
|
next = module.indexOf("/", firstSlash + 1);
|
||||||
|
dir = module.slice(firstSlash + 1, next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
subPath = module.slice(
|
||||||
|
firstSlash + 1,
|
||||||
|
lastSlash + 1
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (p in requireCache) {
|
if (p in requireCache) {
|
||||||
return requireCache[p].exports;
|
return requireCache[p].exports;
|
||||||
|
@ -262,6 +285,9 @@ const describeCases = config => {
|
||||||
};
|
};
|
||||||
requireCache[p] = m;
|
requireCache[p] = m;
|
||||||
let runInNewContext = false;
|
let runInNewContext = false;
|
||||||
|
let oldCurrentScript = document.currentScript;
|
||||||
|
document.currentScript = new CurrentScript(subPath);
|
||||||
|
|
||||||
const moduleScope = {
|
const moduleScope = {
|
||||||
require: _require.bind(
|
require: _require.bind(
|
||||||
null,
|
null,
|
||||||
|
@ -357,6 +383,10 @@ const describeCases = config => {
|
||||||
? vm.runInNewContext(code, globalContext, p)
|
? vm.runInNewContext(code, globalContext, p)
|
||||||
: vm.runInThisContext(code, p);
|
: vm.runInThisContext(code, p);
|
||||||
fn.call(m.exports, moduleScope);
|
fn.call(m.exports, moduleScope);
|
||||||
|
|
||||||
|
//restore state
|
||||||
|
document.currentScript = oldCurrentScript;
|
||||||
|
|
||||||
return m.exports;
|
return m.exports;
|
||||||
} else if (
|
} else if (
|
||||||
testConfig.modules &&
|
testConfig.modules &&
|
||||||
|
|
|
@ -303,11 +303,12 @@ describe("Defaults", () => {
|
||||||
"hotUpdateMainFilename": "[fullhash].hot-update.json",
|
"hotUpdateMainFilename": "[fullhash].hot-update.json",
|
||||||
"iife": true,
|
"iife": true,
|
||||||
"importFunctionName": "import",
|
"importFunctionName": "import",
|
||||||
|
"importMetaName": "import.meta",
|
||||||
"library": undefined,
|
"library": undefined,
|
||||||
"module": false,
|
"module": false,
|
||||||
"path": "<cwd>/dist",
|
"path": "<cwd>/dist",
|
||||||
"pathinfo": false,
|
"pathinfo": false,
|
||||||
"publicPath": "",
|
"publicPath": "auto",
|
||||||
"scriptType": false,
|
"scriptType": false,
|
||||||
"sourceMapFilename": "[file].map[query]",
|
"sourceMapFilename": "[file].map[query]",
|
||||||
"sourcePrefix": undefined,
|
"sourcePrefix": undefined,
|
||||||
|
@ -972,6 +973,9 @@ describe("Defaults", () => {
|
||||||
- "globalObject": "self",
|
- "globalObject": "self",
|
||||||
+ "globalObject": "global",
|
+ "globalObject": "global",
|
||||||
@@ ... @@
|
@@ ... @@
|
||||||
|
- "publicPath": "auto",
|
||||||
|
+ "publicPath": "",
|
||||||
|
@@ ... @@
|
||||||
- "wasmLoading": "fetch",
|
- "wasmLoading": "fetch",
|
||||||
+ "wasmLoading": "async-node",
|
+ "wasmLoading": "async-node",
|
||||||
@@ ... @@
|
@@ ... @@
|
||||||
|
@ -1096,6 +1100,9 @@ describe("Defaults", () => {
|
||||||
- "globalObject": "self",
|
- "globalObject": "self",
|
||||||
+ "globalObject": "global",
|
+ "globalObject": "global",
|
||||||
@@ ... @@
|
@@ ... @@
|
||||||
|
- "publicPath": "auto",
|
||||||
|
+ "publicPath": "",
|
||||||
|
@@ ... @@
|
||||||
- "wasmLoading": "fetch",
|
- "wasmLoading": "fetch",
|
||||||
+ "wasmLoading": "async-node",
|
+ "wasmLoading": "async-node",
|
||||||
@@ ... @@
|
@@ ... @@
|
||||||
|
@ -1202,6 +1209,9 @@ describe("Defaults", () => {
|
||||||
- "globalObject": "self",
|
- "globalObject": "self",
|
||||||
+ "globalObject": "global",
|
+ "globalObject": "global",
|
||||||
@@ ... @@
|
@@ ... @@
|
||||||
|
- "publicPath": "auto",
|
||||||
|
+ "publicPath": "",
|
||||||
|
@@ ... @@
|
||||||
- "wasmLoading": "fetch",
|
- "wasmLoading": "fetch",
|
||||||
+ "wasmLoading": "async-node",
|
+ "wasmLoading": "async-node",
|
||||||
@@ ... @@
|
@@ ... @@
|
||||||
|
|
|
@ -66,6 +66,8 @@ const describeCases = config => {
|
||||||
options.output.chunkFilename = "[name].chunk.[fullhash].js";
|
options.output.chunkFilename = "[name].chunk.[fullhash].js";
|
||||||
if (options.output.pathinfo === undefined)
|
if (options.output.pathinfo === undefined)
|
||||||
options.output.pathinfo = true;
|
options.output.pathinfo = true;
|
||||||
|
if (options.output.publicPath === undefined)
|
||||||
|
options.output.publicPath = "";
|
||||||
if (options.output.library === undefined)
|
if (options.output.library === undefined)
|
||||||
options.output.library = { type: "commonjs2" };
|
options.output.library = { type: "commonjs2" };
|
||||||
if (!options.optimization) options.optimization = {};
|
if (!options.optimization) options.optimization = {};
|
||||||
|
|
|
@ -173,10 +173,10 @@ describe("Stats", () => {
|
||||||
"assets": Array [
|
"assets": Array [
|
||||||
Object {
|
Object {
|
||||||
"name": "entryB.js",
|
"name": "entryB.js",
|
||||||
"size": 2185,
|
"size": 2698,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"assetsSize": 2185,
|
"assetsSize": 2698,
|
||||||
"auxiliaryAssets": undefined,
|
"auxiliaryAssets": undefined,
|
||||||
"auxiliaryAssetsSize": 0,
|
"auxiliaryAssetsSize": 0,
|
||||||
"childAssets": undefined,
|
"childAssets": undefined,
|
||||||
|
@ -220,10 +220,10 @@ describe("Stats", () => {
|
||||||
"filteredRelated": undefined,
|
"filteredRelated": undefined,
|
||||||
"info": Object {
|
"info": Object {
|
||||||
"minimized": true,
|
"minimized": true,
|
||||||
"size": 2185,
|
"size": 2698,
|
||||||
},
|
},
|
||||||
"name": "entryB.js",
|
"name": "entryB.js",
|
||||||
"size": 2185,
|
"size": 2698,
|
||||||
"type": "asset",
|
"type": "asset",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
|
|
|
@ -496,7 +496,7 @@ describe("Validation", () => {
|
||||||
expect(msg).toMatchInlineSnapshot(`
|
expect(msg).toMatchInlineSnapshot(`
|
||||||
"Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
|
"Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
|
||||||
- configuration.output has an unknown property 'ecmaVersion'. These properties are valid:
|
- configuration.output has an unknown property 'ecmaVersion'. These properties are valid:
|
||||||
object { assetModuleFilename?, auxiliaryComment?, charset?, chunkFilename?, chunkFormat?, chunkLoadTimeout?, chunkLoading?, chunkLoadingGlobal?, compareBeforeEmit?, crossOriginLoading?, devtoolFallbackModuleFilenameTemplate?, devtoolModuleFilenameTemplate?, devtoolNamespace?, enabledChunkLoadingTypes?, enabledLibraryTypes?, enabledWasmLoadingTypes?, environment?, filename?, globalObject?, hashDigest?, hashDigestLength?, hashFunction?, hashSalt?, hotUpdateChunkFilename?, hotUpdateGlobal?, hotUpdateMainFilename?, iife?, importFunctionName?, library?, libraryExport?, libraryTarget?, module?, path?, pathinfo?, publicPath?, scriptType?, sourceMapFilename?, sourcePrefix?, strictModuleExceptionHandling?, umdNamedDefine?, uniqueName?, wasmLoading?, webassemblyModuleFilename?, workerChunkLoading?, workerWasmLoading? }
|
object { assetModuleFilename?, auxiliaryComment?, charset?, chunkFilename?, chunkFormat?, chunkLoadTimeout?, chunkLoading?, chunkLoadingGlobal?, compareBeforeEmit?, crossOriginLoading?, devtoolFallbackModuleFilenameTemplate?, devtoolModuleFilenameTemplate?, devtoolNamespace?, enabledChunkLoadingTypes?, enabledLibraryTypes?, enabledWasmLoadingTypes?, environment?, filename?, globalObject?, hashDigest?, hashDigestLength?, hashFunction?, hashSalt?, hotUpdateChunkFilename?, hotUpdateGlobal?, hotUpdateMainFilename?, iife?, importFunctionName?, importMetaName?, library?, libraryExport?, libraryTarget?, module?, path?, pathinfo?, publicPath?, scriptType?, sourceMapFilename?, sourcePrefix?, strictModuleExceptionHandling?, umdNamedDefine?, uniqueName?, wasmLoading?, webassemblyModuleFilename?, workerChunkLoading?, workerWasmLoading? }
|
||||||
-> Options affecting the output of the compilation. \`output\` options tell webpack how to write the compiled files to disk.
|
-> Options affecting the output of the compilation. \`output\` options tell webpack how to write the compiled files to disk.
|
||||||
Did you mean output.environment?"
|
Did you mean output.environment?"
|
||||||
`)
|
`)
|
||||||
|
|
|
@ -2445,6 +2445,19 @@ Object {
|
||||||
"multiple": false,
|
"multiple": false,
|
||||||
"simpleType": "string",
|
"simpleType": "string",
|
||||||
},
|
},
|
||||||
|
"output-import-meta-name": Object {
|
||||||
|
"configs": Array [
|
||||||
|
Object {
|
||||||
|
"description": "The name of the native import.meta object (can be exchanged for a polyfill).",
|
||||||
|
"multiple": false,
|
||||||
|
"path": "output.importMetaName",
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"description": "The name of the native import.meta object (can be exchanged for a polyfill).",
|
||||||
|
"multiple": false,
|
||||||
|
"simpleType": "string",
|
||||||
|
},
|
||||||
"output-library": Object {
|
"output-library": Object {
|
||||||
"configs": Array [
|
"configs": Array [
|
||||||
Object {
|
Object {
|
||||||
|
@ -2783,6 +2796,15 @@ Object {
|
||||||
},
|
},
|
||||||
"output-public-path": Object {
|
"output-public-path": Object {
|
||||||
"configs": Array [
|
"configs": Array [
|
||||||
|
Object {
|
||||||
|
"description": "The \`publicPath\` specifies the public URL address of the output files when referenced in a browser.",
|
||||||
|
"multiple": false,
|
||||||
|
"path": "output.publicPath",
|
||||||
|
"type": "enum",
|
||||||
|
"values": Array [
|
||||||
|
"auto",
|
||||||
|
],
|
||||||
|
},
|
||||||
Object {
|
Object {
|
||||||
"description": "The \`publicPath\` specifies the public URL address of the output files when referenced in a browser.",
|
"description": "The \`publicPath\` specifies the public URL address of the output files when referenced in a browser.",
|
||||||
"multiple": false,
|
"multiple": false,
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -5,6 +5,7 @@ module.exports = {
|
||||||
devtool: false,
|
devtool: false,
|
||||||
output: {
|
output: {
|
||||||
filename: "deep/path/[name].js",
|
filename: "deep/path/[name].js",
|
||||||
assetModuleFilename: "[path][name][ext]"
|
assetModuleFilename: "[path][name][ext]",
|
||||||
|
publicPath: ""
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
import asset from "./asset.jpg";
|
||||||
|
|
||||||
|
it("should define public path", () => {
|
||||||
|
expect(asset).toBe("asset.jpg");
|
||||||
|
});
|
|
@ -0,0 +1,16 @@
|
||||||
|
/** @type {import("../../../../").Configuration} */
|
||||||
|
module.exports = {
|
||||||
|
mode: "none",
|
||||||
|
target: "node",
|
||||||
|
output: {
|
||||||
|
assetModuleFilename: "[name][ext]"
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.jpg$/,
|
||||||
|
type: "asset/resource"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,5 @@
|
||||||
|
import asset from "./asset.jpg";
|
||||||
|
|
||||||
|
it("should define public path", () => {
|
||||||
|
expect(asset).toBe("http://test.co/path/asset.jpg");
|
||||||
|
});
|
|
@ -0,0 +1,10 @@
|
||||||
|
module.exports = {
|
||||||
|
findBundle: function() {
|
||||||
|
return [
|
||||||
|
"./index.mjs"
|
||||||
|
];
|
||||||
|
},
|
||||||
|
moduleScope(scope) {
|
||||||
|
scope.pseudoImport = { meta: { url: "http://test.co/path/index.js" } };
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,19 @@
|
||||||
|
/** @type {import("../../../../").Configuration} */
|
||||||
|
module.exports = {
|
||||||
|
mode: "none",
|
||||||
|
target: "electron-renderer",
|
||||||
|
output: {
|
||||||
|
assetModuleFilename: "[name][ext]",
|
||||||
|
importMetaName: "pseudoImport.meta",
|
||||||
|
scriptType: "module",
|
||||||
|
filename: "index.mjs"
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.jpg$/,
|
||||||
|
type: "asset/resource"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,5 @@
|
||||||
|
import asset from "./asset.jpg";
|
||||||
|
|
||||||
|
it("should define public path", () => {
|
||||||
|
expect(asset).toBe("https://test.cases/path/inner1/inner2/../../asset.jpg");
|
||||||
|
});
|
|
@ -0,0 +1,5 @@
|
||||||
|
import asset from "./asset.jpg";
|
||||||
|
|
||||||
|
it("should define public path", () => {
|
||||||
|
expect(asset).toBe("https://test.cases/path/asset.jpg");
|
||||||
|
});
|
|
@ -0,0 +1,8 @@
|
||||||
|
module.exports = {
|
||||||
|
findBundle: function() {
|
||||||
|
return [
|
||||||
|
"./inner1/inner2/a.js",
|
||||||
|
"./b.js"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,25 @@
|
||||||
|
/** @type {import("../../../../").Configuration} */
|
||||||
|
module.exports = {
|
||||||
|
mode: "none",
|
||||||
|
target: "web",
|
||||||
|
entry() {
|
||||||
|
return {
|
||||||
|
a: "./a",
|
||||||
|
b: "./b"
|
||||||
|
};
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
filename: data => {
|
||||||
|
return data.chunk.name === "a" ? `inner1/inner2/[name].js` : "[name].js";
|
||||||
|
},
|
||||||
|
assetModuleFilename: "[name][ext]"
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.jpg$/,
|
||||||
|
type: "asset/resource"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,8 @@
|
||||||
|
class CurrentScript {
|
||||||
|
constructor(path = "", type = "text/javascript") {
|
||||||
|
this.src = `https://test.cases/path/${path}index.js`;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = CurrentScript;
|
|
@ -10,6 +10,9 @@ module.exports = {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
output: {
|
||||||
|
publicPath: ""
|
||||||
|
},
|
||||||
target: "web",
|
target: "web",
|
||||||
node: {
|
node: {
|
||||||
__dirname: false
|
__dirname: false
|
||||||
|
|
|
@ -6036,6 +6036,11 @@ declare interface Output {
|
||||||
*/
|
*/
|
||||||
importFunctionName?: string;
|
importFunctionName?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the native import.meta object (can be exchanged for a polyfill).
|
||||||
|
*/
|
||||||
|
importMetaName?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make the output files a library, exporting the exports of the entry point.
|
* Make the output files a library, exporting the exports of the entry point.
|
||||||
*/
|
*/
|
||||||
|
@ -6280,6 +6285,11 @@ declare interface OutputNormalized {
|
||||||
*/
|
*/
|
||||||
importFunctionName?: string;
|
importFunctionName?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the native import.meta object (can be exchanged for a polyfill).
|
||||||
|
*/
|
||||||
|
importMetaName?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options for library.
|
* Options for library.
|
||||||
*/
|
*/
|
||||||
|
@ -7785,6 +7795,7 @@ declare abstract class RuntimeTemplate {
|
||||||
supportsBigIntLiteral(): boolean;
|
supportsBigIntLiteral(): boolean;
|
||||||
supportsDynamicImport(): boolean;
|
supportsDynamicImport(): boolean;
|
||||||
supportsEcmaScriptModuleSyntax(): boolean;
|
supportsEcmaScriptModuleSyntax(): boolean;
|
||||||
|
supportTemplateLiteral(): boolean;
|
||||||
returningFunction(returnValue?: any, args?: string): string;
|
returningFunction(returnValue?: any, args?: string): string;
|
||||||
basicFunction(args?: any, body?: any): string;
|
basicFunction(args?: any, body?: any): string;
|
||||||
destructureArray(items?: any, value?: any): string;
|
destructureArray(items?: any, value?: any): string;
|
||||||
|
|
Loading…
Reference in New Issue