use output.importMetaName for import.meta
This commit is contained in:
parent
4dc04d1971
commit
f263359fd8
|
@ -466,6 +466,10 @@ export type Iife = boolean;
|
|||
* The name of the native import() function (can be exchanged for a polyfill).
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
|
@ -1760,6 +1764,10 @@ export interface Output {
|
|||
* The name of the native import() function (can be exchanged for a polyfill).
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
|
@ -2427,6 +2435,10 @@ export interface OutputNormalized {
|
|||
* The name of the native import() function (can be exchanged for a polyfill).
|
||||
*/
|
||||
importFunctionName?: ImportFunctionName;
|
||||
/**
|
||||
* The name of the native import.meta object (can be exchanged for a polyfill).
|
||||
*/
|
||||
importMetaName?: ImportMetaName;
|
||||
/**
|
||||
* Options for library.
|
||||
*/
|
||||
|
|
|
@ -537,6 +537,7 @@ const applyOutputDefaults = (
|
|||
F(output, "module", () => !!outputModule);
|
||||
F(output, "iife", () => !output.module);
|
||||
D(output, "importFunctionName", "import");
|
||||
D(output, "importMetaName", "import.meta");
|
||||
F(output, "chunkFilename", () => {
|
||||
const filename = output.filename;
|
||||
if (typeof filename !== "function") {
|
||||
|
|
|
@ -252,6 +252,7 @@ const getNormalizedWebpackOptions = config => {
|
|||
hotUpdateMainFilename: output.hotUpdateMainFilename,
|
||||
iife: output.iife,
|
||||
importFunctionName: output.importFunctionName,
|
||||
importMetaName: output.importMetaName,
|
||||
scriptType: output.scriptType,
|
||||
library: libraryBase && {
|
||||
type:
|
||||
|
|
|
@ -20,7 +20,7 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
|
|||
*/
|
||||
generate() {
|
||||
const { compilation } = this;
|
||||
const { scriptType, importFunctionName } = compilation.outputOptions;
|
||||
const { scriptType, importMetaName } = compilation.outputOptions;
|
||||
const chunkName = compilation.getPath(
|
||||
JavascriptModulesPlugin.getChunkFilenameTemplate(
|
||||
this.chunk,
|
||||
|
@ -35,7 +35,7 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
|
|||
return Template.asString([
|
||||
"var scriptUrl;",
|
||||
scriptType === "module"
|
||||
? `if (typeof ${importFunctionName}.meta.url === "string") scriptUrl = ${importFunctionName}.meta.url`
|
||||
? `if (typeof ${importMetaName}.url === "string") scriptUrl = ${importMetaName}.url`
|
||||
: Template.asString([
|
||||
`if (${RuntimeGlobals.global}.importScripts) scriptUrl = ${RuntimeGlobals.global}.location + "";`,
|
||||
`var document = ${RuntimeGlobals.global}.document;`,
|
||||
|
|
|
@ -780,6 +780,10 @@
|
|||
"description": "The name of the native import() function (can be exchanged for a polyfill).",
|
||||
"type": "string"
|
||||
},
|
||||
"ImportMetaName": {
|
||||
"description": "The name of the native import.meta object (can be exchanged for a polyfill).",
|
||||
"type": "string"
|
||||
},
|
||||
"InfrastructureLogging": {
|
||||
"description": "Options for infrastructure level logging.",
|
||||
"type": "object",
|
||||
|
@ -1868,6 +1872,9 @@
|
|||
"importFunctionName": {
|
||||
"$ref": "#/definitions/ImportFunctionName"
|
||||
},
|
||||
"importMetaName": {
|
||||
"$ref": "#/definitions/ImportMetaName"
|
||||
},
|
||||
"library": {
|
||||
"$ref": "#/definitions/Library"
|
||||
},
|
||||
|
@ -2032,6 +2039,9 @@
|
|||
"importFunctionName": {
|
||||
"$ref": "#/definitions/ImportFunctionName"
|
||||
},
|
||||
"importMetaName": {
|
||||
"$ref": "#/definitions/ImportMetaName"
|
||||
},
|
||||
"library": {
|
||||
"$ref": "#/definitions/LibraryOptions"
|
||||
},
|
||||
|
|
|
@ -6036,6 +6036,11 @@ declare interface Output {
|
|||
*/
|
||||
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.
|
||||
*/
|
||||
|
@ -6280,6 +6285,11 @@ declare interface OutputNormalized {
|
|||
*/
|
||||
importFunctionName?: string;
|
||||
|
||||
/**
|
||||
* The name of the native import.meta object (can be exchanged for a polyfill).
|
||||
*/
|
||||
importMetaName?: string;
|
||||
|
||||
/**
|
||||
* Options for library.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue