@rushstack/set-webpack-public-path-plugin 3.3.15 → 3.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/SetPublicPathPlugin.d.ts.map +1 -1
- package/lib/SetPublicPathPlugin.js.map +1 -1
- package/package.json +39 -38
- package/CHANGELOG.json +0 -6535
- package/CHANGELOG.md +0 -2321
package/dist/tsdoc-metadata.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetPublicPathPlugin.d.ts","sourceRoot":"","sources":["../src/SetPublicPathPlugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"SetPublicPathPlugin.d.ts","sourceRoot":"","sources":["../src/SetPublicPathPlugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AAQxC;;;;GAIG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IAEnD;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;GAIG;AACH,MAAM,WAAW,kCAAmC,SAAQ,4BAA4B;IACtF;;OAEG;IACH,UAAU,CAAC,EAAE;QACX;;;WAGG;QACH,YAAY,CAAC,EAAE,OAAO,CAAC;QAEvB;;WAEG;QACH,IAAI,CAAC,E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,UAAU,EAAE;YAC3B,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE;gBAChC,aAAa,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC;gBACvD,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE;oBACvC,aAAa,CAAC,SAAS,GAAG,aAAa,CAAC,SAAS;yBAC9C,OAAO,CAAC,WAAW,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;yBACtD,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;iBAC3D;aACF;iBAAM,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,YAAY,EAAE;gBAC/C,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC,GAAG,IAAI,CAAC;gBAEtD,aAAa,CAAC,SAAS,GAAG,gBAAgB,CAAC;aAC5C;SACF;QAED,OAAO;YACL,gCAAgC;YAChC,gBAAgB;YAChB,IAAA,oCAAoB,EAAC,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC;YAClD,OAAO;YACP,EAAE;YACF,OAAO,CAAC,MAAM;SACf,CAAC,IAAI,CAAC,QAAG,CAAC,CAAC;IACd,CAAC;CACF;AAnKD,kDAmKC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { EOL } from 'os';\nimport type * as Webpack from 'webpack';\nimport type * as Webpack5 from 'webpack5';\nimport type * as Tapable from 'tapable';\n\nimport { IInternalOptions, getSetPublicPathCode } from './codeGenerator';\n\n/**\n * The base options for setting the webpack public path at runtime.\n *\n * @public\n */\nexport interface ISetWebpackPublicPathOptions {\n /**\n * Use the System.baseURL property if it is defined.\n */\n systemJs?: boolean;\n\n /**\n * Use the specified string as a URL prefix after the SystemJS path or the publicPath option.\n * If neither systemJs nor publicPath is defined, this option will not apply and an exception will be thrown.\n */\n urlPrefix?: string;\n\n /**\n * Use the specified path as the base public path.\n */\n publicPath?: string;\n\n /**\n * Check for a variable with this name on the page and use its value as a regular expression against script paths to\n * the bundle's script. If a value foo is passed into regexVariable, the produced bundle will look for a variable\n * called foo during initialization, and if a foo variable is found, use its value as a regular expression to detect\n * the bundle's script.\n *\n * See the README for more information.\n */\n regexVariable?: string;\n\n /**\n * A function that returns a snippet of code that manipulates the variable with the name that's specified in the\n * parameter. If this parameter isn't provided, no post-processing code is included. The variable must be modified\n * in-place - the processed value should not be returned.\n *\n * See the README for more information.\n */\n getPostProcessScript?: (varName: string) => string;\n\n /**\n * If true, find the last script matching the regexVariable (if it is set). If false, find the first matching script.\n * This can be useful if there are multiple scripts loaded in the DOM that match the regexVariable.\n */\n preferLastFoundScript?: boolean;\n\n /**\n * If true, always include the public path-setting code. Don't try to detect if any chunks or assets are present.\n */\n skipDetection?: boolean;\n}\n\n/**\n * Options for the set-webpack-public-path plugin.\n *\n * @public\n */\nexport interface ISetWebpackPublicPathPluginOptions extends ISetWebpackPublicPathOptions {\n /**\n * An object that describes how the public path should be discovered.\n */\n scriptName?: {\n /**\n * If set to true, use the webpack generated asset's name. This option is not compatible with\n * andy other scriptName options.\n */\n useAssetName?: boolean;\n\n /**\n * A regular expression expressed as a string to be applied to all script paths on the page.\n */\n name?: string;\n\n /**\n * If true, the name property is tokenized.\n *\n * See the README for more information.\n */\n isTokenized?: boolean;\n };\n}\n\ninterface IAsset {\n size(): number;\n source(): string;\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\ndeclare const __dummyWebpack4MainTemplate: Webpack.compilation.MainTemplate;\ninterface IWebpack4ExtendedMainTemplate extends Webpack.compilation.MainTemplate {\n hooks: {\n startup: Tapable.SyncHook<string, Webpack.compilation.Chunk, string>;\n } & typeof __dummyWebpack4MainTemplate.hooks;\n}\n\nconst SHOULD_REPLACE_ASSET_NAME_TOKEN: unique symbol = Symbol(\n 'set-public-path-plugin-should-replace-asset-name'\n);\n\ninterface IExtendedChunk extends Webpack.compilation.Chunk {\n [SHOULD_REPLACE_ASSET_NAME_TOKEN]: boolean;\n}\n\ninterface IStartupCodeOptions {\n source: string;\n chunk: IExtendedChunk;\n hash: string;\n requireFn: string;\n}\n\nconst PLUGIN_NAME: string = 'set-webpack-public-path';\n\nconst ASSET_NAME_TOKEN: string = '-ASSET-NAME-c0ef4f86-b570-44d3-b210-4428c5b7825c';\n\nconst ASSET_NAME_TOKEN_REGEX: RegExp = new RegExp(ASSET_NAME_TOKEN);\n\nfunction escapeRegExp(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\n/**\n * This simple plugin sets the __webpack_public_path__ variable to a value specified in the arguments,\n * optionally appended to the SystemJs baseURL property.\n *\n * @public\n */\nexport class SetPublicPathPlugin implements Webpack.Plugin {\n public options: ISetWebpackPublicPathPluginOptions;\n\n public constructor(options: ISetWebpackPublicPathPluginOptions) {\n this.options = options;\n\n if (options.scriptName) {\n if (options.scriptName.useAssetName && options.scriptName.name) {\n throw new Error('scriptName.userAssetName and scriptName.name must not be used together');\n } else if (options.scriptName.isTokenized && !options.scriptName.name) {\n throw new Error('scriptName.isTokenized is only valid if scriptName.name is set');\n }\n }\n }\n\n public apply(compiler: Webpack.Compiler): void {\n const isWebpack3OrEarlier: boolean = !compiler.hooks;\n\n if (isWebpack3OrEarlier) {\n throw new Error(`The ${SetPublicPathPlugin.name} plugin requires Webpack 4 or Webpack 5`);\n }\n\n const webpackVersion: string | undefined = (\n compiler as unknown as Webpack5.Compiler | { webpack: undefined }\n ).webpack?.version;\n const webpackMajorVersion: number = webpackVersion\n ? Number(webpackVersion.substr(0, webpackVersion.indexOf('.')))\n : 4;\n\n compiler.hooks.compilation.tap(\n PLUGIN_NAME,\n (compilation: Webpack.compilation.Compilation | Webpack5.Compilation) => {\n if (webpackMajorVersion === 4) {\n const webpack4Compilation: Webpack.compilation.Compilation =\n compilation as Webpack.compilation.Compilation;\n const mainTemplate: IWebpack4ExtendedMainTemplate =\n webpack4Compilation.mainTemplate as IWebpack4ExtendedMainTemplate;\n mainTemplate.hooks.startup.tap(\n PLUGIN_NAME,\n (source: string, chunk: Webpack.compilation.Chunk, hash: string) => {\n const extendedChunk: IExtendedChunk = chunk as IExtendedChunk;\n const assetOrChunkFound: boolean =\n !!this.options.skipDetection || this._detectAssetsOrChunks(extendedChunk);\n if (assetOrChunkFound) {\n return this._getStartupCode({\n source,\n chunk: extendedChunk,\n hash,\n requireFn: mainTemplate.requireFn\n });\n } else {\n return source;\n }\n }\n );\n } else {\n // Webpack 5 has its own automatic public path code, so only apply for Webpack 4\n const Webpack5Error: typeof Webpack5.WebpackError = (compiler as unknown as Webpack5.Compiler)\n .webpack.WebpackError;\n // Don't bother importing node-core-library for this\n const thisPackageJson: { name: string } = require('../package.json');\n compilation.warnings.push(\n new Webpack5Error(\n `Webpack 5 supports its own automatic public path detection, ` +\n `so ${thisPackageJson.name} won't do anything in this compilation.`\n )\n );\n }\n }\n );\n\n // Webpack 5 has its own automatic public path code, so only apply for Webpack 4\n if (webpackMajorVersion === 4) {\n compiler.hooks.emit.tap(\n PLUGIN_NAME,\n (compilation: Webpack.compilation.Compilation | Webpack5.Compilation) => {\n for (const chunkGroup of compilation.chunkGroups) {\n for (const chunk of chunkGroup.chunks) {\n if (chunk[SHOULD_REPLACE_ASSET_NAME_TOKEN]) {\n for (const assetFilename of chunk.files) {\n let escapedAssetFilename: string;\n if (assetFilename.match(/\\.map$/)) {\n // Trim the \".map\" extension\n escapedAssetFilename = assetFilename.substr(\n 0,\n assetFilename.length - 4 /* '.map'.length */\n );\n escapedAssetFilename = escapeRegExp(escapedAssetFilename);\n // source in sourcemaps is JSON-encoded\n escapedAssetFilename = JSON.stringify(escapedAssetFilename);\n // Trim the quotes from the JSON encoding\n escapedAssetFilename = escapedAssetFilename.substring(1, escapedAssetFilename.length - 1);\n } else {\n escapedAssetFilename = escapeRegExp(assetFilename);\n }\n\n const asset: IAsset = compilation.assets[assetFilename];\n const originalAssetSource: string = asset.source();\n const originalAssetSize: number = asset.size();\n\n const newAssetSource: string = originalAssetSource.replace(\n ASSET_NAME_TOKEN_REGEX,\n escapedAssetFilename\n );\n const sizeDifference: number = assetFilename.length - ASSET_NAME_TOKEN.length;\n asset.source = () => newAssetSource;\n asset.size = () => originalAssetSize + sizeDifference;\n }\n }\n }\n }\n }\n );\n }\n }\n\n private _detectAssetsOrChunks(chunk: IExtendedChunk): boolean {\n for (const chunkGroup of chunk.groupsIterable) {\n if (chunkGroup.childrenIterable.size > 0) {\n return true;\n }\n }\n\n for (const innerModule of chunk.modulesIterable) {\n if (innerModule.buildInfo.assets && Object.keys(innerModule.buildInfo.assets).length > 0) {\n return true;\n }\n }\n\n return false;\n }\n\n private _getStartupCode(options: IStartupCodeOptions): string {\n const moduleOptions: IInternalOptions = { ...this.options };\n\n // If this module has ownership over any chunks or assets, inject the public path code\n moduleOptions.webpackPublicPathVariable = `${options.requireFn}.p`;\n moduleOptions.linePrefix = ' ';\n\n if (this.options.scriptName) {\n if (this.options.scriptName.name) {\n moduleOptions.regexName = this.options.scriptName.name;\n if (this.options.scriptName.isTokenized) {\n moduleOptions.regexName = moduleOptions.regexName\n .replace(/\\[name\\]/g, escapeRegExp(options.chunk.name))\n .replace(/\\[hash\\]/g, options.chunk.renderedHash || '');\n }\n } else if (this.options.scriptName.useAssetName) {\n options.chunk[SHOULD_REPLACE_ASSET_NAME_TOKEN] = true;\n\n moduleOptions.regexName = ASSET_NAME_TOKEN;\n }\n }\n\n return [\n '// Set the webpack public path',\n '(function () {',\n getSetPublicPathCode(moduleOptions, console.error),\n '})();',\n '',\n options.source\n ].join(EOL);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SetPublicPathPlugin.js","sourceRoot":"","sources":["../src/SetPublicPathPlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,2BAAyB;AAOzB,mD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;gBAC/C,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC,GAAG,IAAI,CAAC;gBAEtD,aAAa,CAAC,SAAS,GAAG,gBAAgB,CAAC;aAC5C;SACF;QAED,OAAO;YACL,gCAAgC;YAChC,gBAAgB;YAChB,IAAA,oCAAoB,EAAC,aAAa,EAAE,OAAO,CAAC,KAAK,CAAC;YAClD,OAAO;YACP,EAAE;YACF,OAAO,CAAC,MAAM;SACf,CAAC,IAAI,CAAC,QAAG,CAAC,CAAC;IACd,CAAC;CACF;AAnKD,kDAmKC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { EOL } from 'os';\nimport type * as Webpack from 'webpack';\nimport type * as Tapable from 'tapable';\n\n// Workaround for https://github.com/pnpm/pnpm/issues/4301\nimport type * as Webpack5 from '@rushstack/heft-webpack5-plugin/node_modules/webpack';\n\nimport { IInternalOptions, getSetPublicPathCode } from './codeGenerator';\n\n/**\n * The base options for setting the webpack public path at runtime.\n *\n * @public\n */\nexport interface ISetWebpackPublicPathOptions {\n /**\n * Use the System.baseURL property if it is defined.\n */\n systemJs?: boolean;\n\n /**\n * Use the specified string as a URL prefix after the SystemJS path or the publicPath option.\n * If neither systemJs nor publicPath is defined, this option will not apply and an exception will be thrown.\n */\n urlPrefix?: string;\n\n /**\n * Use the specified path as the base public path.\n */\n publicPath?: string;\n\n /**\n * Check for a variable with this name on the page and use its value as a regular expression against script paths to\n * the bundle's script. If a value foo is passed into regexVariable, the produced bundle will look for a variable\n * called foo during initialization, and if a foo variable is found, use its value as a regular expression to detect\n * the bundle's script.\n *\n * See the README for more information.\n */\n regexVariable?: string;\n\n /**\n * A function that returns a snippet of code that manipulates the variable with the name that's specified in the\n * parameter. If this parameter isn't provided, no post-processing code is included. The variable must be modified\n * in-place - the processed value should not be returned.\n *\n * See the README for more information.\n */\n getPostProcessScript?: (varName: string) => string;\n\n /**\n * If true, find the last script matching the regexVariable (if it is set). If false, find the first matching script.\n * This can be useful if there are multiple scripts loaded in the DOM that match the regexVariable.\n */\n preferLastFoundScript?: boolean;\n\n /**\n * If true, always include the public path-setting code. Don't try to detect if any chunks or assets are present.\n */\n skipDetection?: boolean;\n}\n\n/**\n * Options for the set-webpack-public-path plugin.\n *\n * @public\n */\nexport interface ISetWebpackPublicPathPluginOptions extends ISetWebpackPublicPathOptions {\n /**\n * An object that describes how the public path should be discovered.\n */\n scriptName?: {\n /**\n * If set to true, use the webpack generated asset's name. This option is not compatible with\n * andy other scriptName options.\n */\n useAssetName?: boolean;\n\n /**\n * A regular expression expressed as a string to be applied to all script paths on the page.\n */\n name?: string;\n\n /**\n * If true, the name property is tokenized.\n *\n * See the README for more information.\n */\n isTokenized?: boolean;\n };\n}\n\ninterface IAsset {\n size(): number;\n source(): string;\n}\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\ndeclare const __dummyWebpack4MainTemplate: Webpack.compilation.MainTemplate;\ninterface IWebpack4ExtendedMainTemplate extends Webpack.compilation.MainTemplate {\n hooks: {\n startup: Tapable.SyncHook<string, Webpack.compilation.Chunk, string>;\n } & typeof __dummyWebpack4MainTemplate.hooks;\n}\n\nconst SHOULD_REPLACE_ASSET_NAME_TOKEN: unique symbol = Symbol(\n 'set-public-path-plugin-should-replace-asset-name'\n);\n\ninterface IExtendedChunk extends Webpack.compilation.Chunk {\n [SHOULD_REPLACE_ASSET_NAME_TOKEN]: boolean;\n}\n\ninterface IStartupCodeOptions {\n source: string;\n chunk: IExtendedChunk;\n hash: string;\n requireFn: string;\n}\n\nconst PLUGIN_NAME: string = 'set-webpack-public-path';\n\nconst ASSET_NAME_TOKEN: string = '-ASSET-NAME-c0ef4f86-b570-44d3-b210-4428c5b7825c';\n\nconst ASSET_NAME_TOKEN_REGEX: RegExp = new RegExp(ASSET_NAME_TOKEN);\n\nfunction escapeRegExp(str: string): string {\n return str.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\n/**\n * This simple plugin sets the __webpack_public_path__ variable to a value specified in the arguments,\n * optionally appended to the SystemJs baseURL property.\n *\n * @public\n */\nexport class SetPublicPathPlugin implements Webpack.Plugin {\n public options: ISetWebpackPublicPathPluginOptions;\n\n public constructor(options: ISetWebpackPublicPathPluginOptions) {\n this.options = options;\n\n if (options.scriptName) {\n if (options.scriptName.useAssetName && options.scriptName.name) {\n throw new Error('scriptName.userAssetName and scriptName.name must not be used together');\n } else if (options.scriptName.isTokenized && !options.scriptName.name) {\n throw new Error('scriptName.isTokenized is only valid if scriptName.name is set');\n }\n }\n }\n\n public apply(compiler: Webpack.Compiler): void {\n const isWebpack3OrEarlier: boolean = !compiler.hooks;\n\n if (isWebpack3OrEarlier) {\n throw new Error(`The ${SetPublicPathPlugin.name} plugin requires Webpack 4 or Webpack 5`);\n }\n\n const webpackVersion: string | undefined = (\n compiler as unknown as Webpack5.Compiler | { webpack: undefined }\n ).webpack?.version;\n const webpackMajorVersion: number = webpackVersion\n ? Number(webpackVersion.substr(0, webpackVersion.indexOf('.')))\n : 4;\n\n compiler.hooks.compilation.tap(\n PLUGIN_NAME,\n (compilation: Webpack.compilation.Compilation | Webpack5.Compilation) => {\n if (webpackMajorVersion === 4) {\n const webpack4Compilation: Webpack.compilation.Compilation =\n compilation as Webpack.compilation.Compilation;\n const mainTemplate: IWebpack4ExtendedMainTemplate =\n webpack4Compilation.mainTemplate as IWebpack4ExtendedMainTemplate;\n mainTemplate.hooks.startup.tap(\n PLUGIN_NAME,\n (source: string, chunk: Webpack.compilation.Chunk, hash: string) => {\n const extendedChunk: IExtendedChunk = chunk as IExtendedChunk;\n const assetOrChunkFound: boolean =\n !!this.options.skipDetection || this._detectAssetsOrChunks(extendedChunk);\n if (assetOrChunkFound) {\n return this._getStartupCode({\n source,\n chunk: extendedChunk,\n hash,\n requireFn: mainTemplate.requireFn\n });\n } else {\n return source;\n }\n }\n );\n } else {\n // Webpack 5 has its own automatic public path code, so only apply for Webpack 4\n const Webpack5Error: typeof Webpack5.WebpackError = (compiler as unknown as Webpack5.Compiler)\n .webpack.WebpackError;\n // Don't bother importing node-core-library for this\n const thisPackageJson: { name: string } = require('../package.json');\n compilation.warnings.push(\n new Webpack5Error(\n `Webpack 5 supports its own automatic public path detection, ` +\n `so ${thisPackageJson.name} won't do anything in this compilation.`\n )\n );\n }\n }\n );\n\n // Webpack 5 has its own automatic public path code, so only apply for Webpack 4\n if (webpackMajorVersion === 4) {\n compiler.hooks.emit.tap(\n PLUGIN_NAME,\n (compilation: Webpack.compilation.Compilation | Webpack5.Compilation) => {\n for (const chunkGroup of compilation.chunkGroups) {\n for (const chunk of chunkGroup.chunks) {\n if (chunk[SHOULD_REPLACE_ASSET_NAME_TOKEN]) {\n for (const assetFilename of chunk.files) {\n let escapedAssetFilename: string;\n if (assetFilename.match(/\\.map$/)) {\n // Trim the \".map\" extension\n escapedAssetFilename = assetFilename.substr(\n 0,\n assetFilename.length - 4 /* '.map'.length */\n );\n escapedAssetFilename = escapeRegExp(escapedAssetFilename);\n // source in sourcemaps is JSON-encoded\n escapedAssetFilename = JSON.stringify(escapedAssetFilename);\n // Trim the quotes from the JSON encoding\n escapedAssetFilename = escapedAssetFilename.substring(1, escapedAssetFilename.length - 1);\n } else {\n escapedAssetFilename = escapeRegExp(assetFilename);\n }\n\n const asset: IAsset = compilation.assets[assetFilename];\n const originalAssetSource: string = asset.source();\n const originalAssetSize: number = asset.size();\n\n const newAssetSource: string = originalAssetSource.replace(\n ASSET_NAME_TOKEN_REGEX,\n escapedAssetFilename\n );\n const sizeDifference: number = assetFilename.length - ASSET_NAME_TOKEN.length;\n asset.source = () => newAssetSource;\n asset.size = () => originalAssetSize + sizeDifference;\n }\n }\n }\n }\n }\n );\n }\n }\n\n private _detectAssetsOrChunks(chunk: IExtendedChunk): boolean {\n for (const chunkGroup of chunk.groupsIterable) {\n if (chunkGroup.childrenIterable.size > 0) {\n return true;\n }\n }\n\n for (const innerModule of chunk.modulesIterable) {\n if (innerModule.buildInfo.assets && Object.keys(innerModule.buildInfo.assets).length > 0) {\n return true;\n }\n }\n\n return false;\n }\n\n private _getStartupCode(options: IStartupCodeOptions): string {\n const moduleOptions: IInternalOptions = { ...this.options };\n\n // If this module has ownership over any chunks or assets, inject the public path code\n moduleOptions.webpackPublicPathVariable = `${options.requireFn}.p`;\n moduleOptions.linePrefix = ' ';\n\n if (this.options.scriptName) {\n if (this.options.scriptName.name) {\n moduleOptions.regexName = this.options.scriptName.name;\n if (this.options.scriptName.isTokenized) {\n moduleOptions.regexName = moduleOptions.regexName\n .replace(/\\[name\\]/g, escapeRegExp(options.chunk.name))\n .replace(/\\[hash\\]/g, options.chunk.renderedHash || '');\n }\n } else if (this.options.scriptName.useAssetName) {\n options.chunk[SHOULD_REPLACE_ASSET_NAME_TOKEN] = true;\n\n moduleOptions.regexName = ASSET_NAME_TOKEN;\n }\n }\n\n return [\n '// Set the webpack public path',\n '(function () {',\n getSetPublicPathCode(moduleOptions, console.error),\n '})();',\n '',\n options.source\n ].join(EOL);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,39 +1,40 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
2
|
+
"name": "@rushstack/set-webpack-public-path-plugin",
|
|
3
|
+
"version": "3.3.18",
|
|
4
|
+
"description": "This plugin sets the webpack public path at runtime.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "dist/set-webpack-public-path-plugin.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/microsoft/rushstack.git",
|
|
11
|
+
"directory": "webpack/set-webpack-public-path-plugin"
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"@types/webpack": "^4.39.8",
|
|
15
|
+
"webpack": "^5.35.1"
|
|
16
|
+
},
|
|
17
|
+
"peerDependenciesMeta": {
|
|
18
|
+
"@types/webpack": {
|
|
19
|
+
"optional": true
|
|
20
|
+
},
|
|
21
|
+
"webpack": {
|
|
22
|
+
"optional": true
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@rushstack/eslint-config": "2.5.2",
|
|
27
|
+
"@rushstack/heft": "0.44.4",
|
|
28
|
+
"@rushstack/heft-node-rig": "1.8.2",
|
|
29
|
+
"@rushstack/heft-webpack5-plugin": "0.5.2",
|
|
30
|
+
"@types/heft-jest": "1.0.1",
|
|
31
|
+
"@types/node": "12.20.24",
|
|
32
|
+
"@types/tapable": "1.0.6",
|
|
33
|
+
"@types/webpack": "4.41.24"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "heft build --clean",
|
|
37
|
+
"_phase:build": "heft build --clean"
|
|
38
|
+
},
|
|
39
|
+
"readme": "# set-webpack-public-path plugin for webpack\n\n## Installation\n\n`npm install @rushstack/set-webpack-public-path-plugin --save-dev`\n\n## Overview\n\nThis simple plugin sets the `__webpack_public_path__` variable to\na value specified in the arguments, optionally appended to the SystemJs baseURL\nproperty.\n\n# Plugin\n\nTo use the plugin, add it to the `plugins` array of your Webpack config. For example:\n\n```JavaScript\nimport { SetPublicPathPlugin } from '@rushstack/set-webpack-public-path-plugin';\n\n{\n plugins: [\n new SetPublicPathPlugin( /* webpackPublicPathOptions */ )\n ]\n}\n```\n\n## Options\n\n#### `scriptName = { }`\n\nThis parameter is an object that takes three properties: a string property `name`, a boolean property `isTokenized`,\nand a boolean property `useAssetName`\n\nThe `name` property is a regular expression string that is applied to all script URLs on the page. The last directory\nof the URL that matches the regular expression is used as the public path. For example, if the `name` property\nis set to `my\\-bundle_?[a-zA-Z0-9-_]*\\.js` and a script's URL is `https://mycdn.net/files/build_id/assets/my-bundle_10fae182eb.js`,\nthe public path will be set to `https://mycdn.net/files/build_id/assets/`.\n\nIf the `isTokenized` parameter is set to `true`, the regular expression string in `name` is treated as a tokenized\nstring. The supported tokens are `[name]` and `[hash]`. Instances of the `[name]` substring are replaced with the\nchunk's name, and instances of the `[hash]` substring are replaced with the chunk's rendered hash. The name\nis regular expression-escaped. For example, if the `name` property is set to `[name]_?[a-zA-Z0-9-_]*\\.js`,\n`isTokenized` is set to `true`, and the chunk's name is `my-bundle`, and a script's URL is\n`https://mycdn.net/files/build_id/assets/my-bundle_10fae182eb.js`, the public path will be set to\n`https://mycdn.net/files/build_id/assets/`.\n\nIf the `useAssetName` property is set, the plugin will use the Webpack-produced asset name as it would the `name`\nproperty. `useAssetName` is exclusive to `name` and `isTokenized`.\n\nThis option is exclusive to other options. If it is set, `systemJs`, `publicPath`, and `urlPrefix` will be ignored.\n\n#### `systemJs = true`\n\nUse `System.baseURL` if it is defined.\n\n#### `publicPath = '...'`\n\nUse the specified path as the base public path. If `urlPrefix` is also defined, the public path will\nbe the concatenation of the two (i.e. - `__webpack_public_path__ = URL.concat({publicPath} + {urlPrefix}`).\nThis option takes precedence over the `systemJs` option.\n\n#### `urlPrefix = '...'`\n\nUse the specified string as a URL prefix after the SystemJS path or the `publicPath` option. If neither\n`systemJs` nor `publicPath` is defined, this option will not apply and an exception will be thrown.\n\n#### `regexVariable = '...'`\n\nCheck for a variable with name `...` on the page and use its value as a regular expression against script paths to\nthe bundle's script. If a value `foo` is passed into `regexVariable`, the produced bundle will look for a variable\ncalled `foo` during initialization, and if a `foo` variable is found, use its value as a regular expression to\ndetect the bundle's script.\n\nFor example, if the `regexVariable` option is set to `scriptRegex` and `scriptName` is set to `{ name: 'myscript' }`,\nconsider two cases:\n\n##### Case 1\n\n```HTML\n<html>\n <head>\n <script>\n var scriptRegex = /thescript/i;\n </script>\n <script src=\"theScript.js\"></script>\n </head>\n\n ...\n</html>\n```\n\nIn this case, because there is a `scriptRegex` variable defined on the page, the bundle will use its value\n(`/thescript/i`) to find the script.\n\n##### Case 2\n\n```HTML\n<html>\n <head>\n <script src=\"myScript.js\"></script>\n </head>\n\n ...\n</html>\n```\n\nIn this case, because there is not a `scriptRegex` variable defined on the page, the bundle will use the value\npassed into the `scriptName` option to find the script.\n\n#### `getPostProcessScript = (variableName) => { ... }`\n\nA function that returns a snippet of code that manipulates the variable with the name that's specified in the\nparameter. If this parameter isn't provided, no post-processing code is included. The variable must be modified\nin-place - the processed value should not be returned. This is useful when non-entry assets are deployed to\na parent directory or subdirectory of the directory to which the entry assets are deployed.\n\nFor example, if this parameter is set to this function\n\n```JavaScript\ngetPostProcessScript = (variableName) => {\n return `${variableName} = ${variableName} + 'assets/';`;\n};\n```\n\nthe public path variable will have `/assets/` appended to the found path.\n\nNote that the existing value of the variable already ends in a slash (`/`).\n\n#### `preferLastFoundScript = false`\n\nIf true, find the last script matching the regexVariable (if it is set). If false, find the first matching script.\nThis can be useful if there are multiple scripts loaded in the DOM that match the regexVariable.\n\n#### `skipDetection = false`\n\nIf true, always include the code snippet to detect the public path regardless of whether chunks or assets are present.\n\n# SystemJS Caveat\n\nWhen modules are loaded with SystemJS (and with the , `scriptLoad: true` meta option) `<script src=\"...\"></script>`\ntags are injected onto the page, evaludated and then immediately removed. This causes an issue because they are removed\nbefore webpack module code begins to execute, so the `publicPath=...` option won't work for modules loaded with SystemJS.\n\nTo circumvent this issue, a small bit of code is availble to that will maintain a global register of script paths\nthat have been inserted onto the page. This code block should be appended to bundles that are expected to be loaded\nwith SystemJS and use the `publicPath=...` option.\n\n## `getGlobalRegisterCode(bool)`\n\nThis function returns a block of JavaScript that maintains a global register of script tags. If the optional boolean parameter\nis set to `true`, the code is not minified. By default, it is minified. You can detect if the plugin may require\nthe global register code by searching for the value of the `registryVariableName` field.\n\n## Usage without registryVariableName\n\n``` javascript\nvar setWebpackPublicPath = require('@rushstack/set-webpack-public-path-plugin');\nvar gulpInsert = require('gulp-insert');\n\ngulp.src('finizlied/webpack/bundle/path')\n .pipe(gulpInsert.append(setWebpackPublicPath.getGlobalRegisterCode(true)))\n .pipe(gulp.dest('dest/path'));\n```\n\n## Usage with registryVariableName\n\n``` javascript\nvar setWebpackPublicPath = require('@rushstack/set-webpack-public-path-plugin');\nvar gulpInsert = require('gulp-insert');\nvar gulpIf = require('gulp-if');\n\nvar detectRegistryVariableName = function (file) {\n return file.contents.toString().indexOf(setWebpackPublicPath.registryVariableName) !== -1;\n};\n\ngulp.src('finizlied/webpack/bundle/path')\n .pipe(gulpIf(detectRegistryVariableName, gulpInsert.append(setWebpackPublicPath.getGlobalRegisterCode(true))))\n .pipe(gulp.dest('dest/path'));\n```\n\n## Links\n\n- [CHANGELOG.md](\n https://github.com/microsoft/rushstack/blob/master/webpack/set-webpack-public-path-plugin/CHANGELOG.md) - Find\n out what's new in the latest version\n\n`@rushstack/set-webpack-public-path-plugin` is part of the [Rush Stack](https://rushstack.io/) family of projects.\n"
|
|
40
|
+
}
|