From 1e5b0b194fe7b8833ecafb5e578d513440d85bcc Mon Sep 17 00:00:00 2001 From: "gaoyuan.1226" Date: Fri, 28 Jun 2024 15:19:31 +0800 Subject: [PATCH] fix: closure HtmlBasicPlugin environment property --- .../tests/__snapshots__/default.test.ts.snap | 277 +-- .../__snapshots__/webpackConfig.test.ts.snap | 138 +- packages/core/src/createContext.ts | 4 - packages/core/src/rspack/HtmlBasicPlugin.ts | 6 +- .../tests/__snapshots__/builder.test.ts.snap | 136 +- .../tests/__snapshots__/default.test.ts.snap | 412 +---- .../tests/__snapshots__/html.test.ts.snap | 1528 +---------------- .../__snapshots__/inlineChunk.test.ts.snap | 274 +-- .../tests/__snapshots__/index.test.ts.snap | 136 +- .../plugin-styled-components/src/index.ts | 48 +- .../tests/__snapshots__/index.test.ts.snap | 4 +- packages/shared/src/types/context.ts | 3 - 12 files changed, 54 insertions(+), 2912 deletions(-) diff --git a/packages/compat/webpack/tests/__snapshots__/default.test.ts.snap b/packages/compat/webpack/tests/__snapshots__/default.test.ts.snap index fc6ea02442..d128bf1a3c 100644 --- a/packages/compat/webpack/tests/__snapshots__/default.test.ts.snap +++ b/packages/compat/webpack/tests/__snapshots__/default.test.ts.snap @@ -330,145 +330,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": { - "browserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "distPath": "/packages/compat/webpack/tests/dist", - "entry": { - "index": "src/index.js", - }, - "htmlPaths": { - "index": "index.html", - }, - "index": 0, - "name": "web", - "normalizedConfig": { - "_privateMeta": { - "configFilePath": "/path/to/rsbuild.config.ts", - }, - "dev": { - "assetPrefix": "/", - "client": { - "host": "", - "overlay": true, - "path": "/rsbuild-hmr", - "port": "", - }, - "hmr": true, - "lazyCompilation": undefined, - "liveReload": true, - "writeToDisk": false, - }, - "html": { - "crossorigin": false, - "inject": "head", - "meta": { - "charset": { - "charset": "UTF-8", - }, - "viewport": "width=device-width, initial-scale=1.0", - }, - "mountId": "root", - "outputStructure": "flat", - "scriptLoading": "defer", - "title": "Rsbuild App", - }, - "output": { - "assetPrefix": "/", - "charset": "ascii", - "cssModules": { - "auto": true, - "exportGlobals": false, - "exportLocalsConvention": "camelCase", - "namedExport": false, - }, - "dataUriLimit": { - "font": 4096, - "image": 4096, - "media": 4096, - "svg": 4096, - }, - "distPath": { - "css": "static/css", - "font": "static/font", - "html": "/", - "image": "static/image", - "js": "static/js", - "media": "static/media", - "root": "dist", - "svg": "static/svg", - "wasm": "static/wasm", - }, - "emitAssets": true, - "filename": {}, - "filenameHash": true, - "injectStyles": false, - "inlineScripts": false, - "inlineStyles": false, - "legalComments": "linked", - "manifest": false, - "minify": true, - "polyfill": "usage", - "sourceMap": { - "css": false, - "js": undefined, - }, - "target": "web", - }, - "performance": { - "buildCache": true, - "chunkSplit": { - "strategy": "split-by-experience", - }, - "printFileSize": true, - "profile": false, - "removeConsole": false, - "removeMomentLocale": false, - }, - "security": { - "nonce": "", - "sri": { - "enable": false, - }, - }, - "server": { - "compress": true, - "host": "0.0.0.0", - "htmlFallback": "index", - "open": false, - "port": 3000, - "printUrls": true, - "strictPort": false, - }, - "source": { - "alias": {}, - "aliasStrategy": "prefer-tsconfig", - "decorators": { - "version": "2022-03", - }, - "define": {}, - "entry": { - "index": "src/index.js", - }, - "preEntry": [], - "tsconfigPath": "/packages/compat/webpack/tests/tsconfig.json", - }, - "tools": { - "cssExtract": { - "loaderOptions": {}, - "pluginOptions": { - "ignoreOrder": true, - }, - }, - }, - }, - "target": "web", - "tsconfigPath": "/packages/compat/webpack/tests/tsconfig.json", - }, + "getEnvironment": [Function], "modifyTagsFn": [Function], "name": "HtmlBasicPlugin", "options": { @@ -899,142 +761,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ "version": 5, }, HtmlBasicPlugin { - "environment": { - "browserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "distPath": "/packages/compat/webpack/tests/dist", - "entry": { - "index": "src/index.js", - }, - "htmlPaths": { - "index": "index.html", - }, - "index": 0, - "name": "web", - "normalizedConfig": { - "dev": { - "assetPrefix": "/", - "client": { - "host": "", - "overlay": true, - "path": "/rsbuild-hmr", - "port": "", - }, - "hmr": true, - "lazyCompilation": undefined, - "liveReload": true, - "writeToDisk": false, - }, - "html": { - "crossorigin": false, - "inject": "head", - "meta": { - "charset": { - "charset": "UTF-8", - }, - "viewport": "width=device-width, initial-scale=1.0", - }, - "mountId": "root", - "outputStructure": "flat", - "scriptLoading": "defer", - "title": "Rsbuild App", - }, - "output": { - "assetPrefix": "/", - "charset": "ascii", - "cssModules": { - "auto": true, - "exportGlobals": false, - "exportLocalsConvention": "camelCase", - "namedExport": false, - }, - "dataUriLimit": { - "font": 4096, - "image": 4096, - "media": 4096, - "svg": 4096, - }, - "distPath": { - "css": "static/css", - "font": "static/font", - "html": "/", - "image": "static/image", - "js": "static/js", - "media": "static/media", - "root": "dist", - "svg": "static/svg", - "wasm": "static/wasm", - }, - "emitAssets": true, - "filename": {}, - "filenameHash": true, - "injectStyles": false, - "inlineScripts": false, - "inlineStyles": false, - "legalComments": "linked", - "manifest": false, - "minify": true, - "polyfill": "usage", - "sourceMap": { - "css": false, - "js": undefined, - }, - "target": "web", - }, - "performance": { - "buildCache": true, - "chunkSplit": { - "strategy": "split-by-experience", - }, - "printFileSize": true, - "profile": false, - "removeConsole": false, - "removeMomentLocale": false, - }, - "security": { - "nonce": "", - "sri": { - "enable": false, - }, - }, - "server": { - "compress": true, - "host": "0.0.0.0", - "htmlFallback": "index", - "open": false, - "port": 3000, - "printUrls": true, - "strictPort": false, - }, - "source": { - "alias": {}, - "aliasStrategy": "prefer-tsconfig", - "decorators": { - "version": "2022-03", - }, - "define": {}, - "entry": { - "index": "src/index.js", - }, - "preEntry": [], - "tsconfigPath": "/packages/compat/webpack/tests/tsconfig.json", - }, - "tools": { - "cssExtract": { - "loaderOptions": {}, - "pluginOptions": { - "ignoreOrder": true, - }, - }, - }, - }, - "target": "web", - "tsconfigPath": "/packages/compat/webpack/tests/tsconfig.json", - }, + "getEnvironment": [Function], "modifyTagsFn": [Function], "name": "HtmlBasicPlugin", "options": { diff --git a/packages/compat/webpack/tests/__snapshots__/webpackConfig.test.ts.snap b/packages/compat/webpack/tests/__snapshots__/webpackConfig.test.ts.snap index 157361389c..0d6f479c23 100644 --- a/packages/compat/webpack/tests/__snapshots__/webpackConfig.test.ts.snap +++ b/packages/compat/webpack/tests/__snapshots__/webpackConfig.test.ts.snap @@ -78,143 +78,7 @@ exports[`webpackConfig > should allow to append and prepend plugins 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": { - "browserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "distPath": "/packages/compat/webpack/tests/dist", - "entry": { - "index": "src/index.js", - }, - "htmlPaths": { - "index": "index.html", - }, - "index": 0, - "name": "web", - "normalizedConfig": { - "dev": { - "assetPrefix": "/", - "client": { - "host": "", - "overlay": true, - "path": "/rsbuild-hmr", - "port": "", - }, - "hmr": true, - "lazyCompilation": undefined, - "liveReload": true, - "writeToDisk": false, - }, - "html": { - "crossorigin": false, - "inject": "head", - "meta": { - "charset": { - "charset": "UTF-8", - }, - "viewport": "width=device-width, initial-scale=1.0", - }, - "mountId": "root", - "outputStructure": "flat", - "scriptLoading": "defer", - "title": "Rsbuild App", - }, - "output": { - "assetPrefix": "/", - "charset": "ascii", - "cssModules": { - "auto": true, - "exportGlobals": false, - "exportLocalsConvention": "camelCase", - "namedExport": false, - }, - "dataUriLimit": { - "font": 4096, - "image": 4096, - "media": 4096, - "svg": 4096, - }, - "distPath": { - "css": "static/css", - "font": "static/font", - "html": "/", - "image": "static/image", - "js": "static/js", - "media": "static/media", - "root": "dist", - "svg": "static/svg", - "wasm": "static/wasm", - }, - "emitAssets": true, - "filename": {}, - "filenameHash": true, - "injectStyles": false, - "inlineScripts": false, - "inlineStyles": false, - "legalComments": "linked", - "manifest": false, - "minify": true, - "polyfill": "usage", - "sourceMap": { - "css": false, - "js": undefined, - }, - "target": "web", - }, - "performance": { - "buildCache": true, - "chunkSplit": { - "strategy": "split-by-experience", - }, - "printFileSize": true, - "profile": false, - "removeConsole": false, - "removeMomentLocale": false, - }, - "security": { - "nonce": "", - "sri": { - "enable": false, - }, - }, - "server": { - "compress": true, - "host": "0.0.0.0", - "htmlFallback": "index", - "open": false, - "port": 3000, - "printUrls": true, - "strictPort": false, - }, - "source": { - "alias": {}, - "aliasStrategy": "prefer-tsconfig", - "decorators": { - "version": "2022-03", - }, - "define": {}, - "entry": { - "index": "src/index.js", - }, - "preEntry": [], - "tsconfigPath": "/packages/compat/webpack/tests/tsconfig.json", - }, - "tools": { - "cssExtract": { - "loaderOptions": {}, - "pluginOptions": { - "ignoreOrder": true, - }, - }, - "webpack": [Function], - }, - }, - "target": "web", - "tsconfigPath": "/packages/compat/webpack/tests/tsconfig.json", - }, + "getEnvironment": [Function], "modifyTagsFn": [Function], "name": "HtmlBasicPlugin", "options": { diff --git a/packages/core/src/createContext.ts b/packages/core/src/createContext.ts index d248786dbe..4f29db614a 100644 --- a/packages/core/src/createContext.ts +++ b/packages/core/src/createContext.ts @@ -46,7 +46,6 @@ async function createContextByConfig( const tsconfigPath = config.source?.tsconfigPath; return { - targets: [], version: RSBUILD_VERSION, rootPath, distPath: '', @@ -169,9 +168,6 @@ export function updateContextByNormalizedConfig( (item) => item.distPath, ); context.distPath = getCommonParentPath(distPaths); - context.targets = Object.values(context.environments).map( - (item) => item.target, - ); } export function createPublicContext( diff --git a/packages/core/src/rspack/HtmlBasicPlugin.ts b/packages/core/src/rspack/HtmlBasicPlugin.ts index 616af0a29e..84fc06a1a9 100644 --- a/packages/core/src/rspack/HtmlBasicPlugin.ts +++ b/packages/core/src/rspack/HtmlBasicPlugin.ts @@ -236,7 +236,7 @@ const addFavicon = (headTags: HtmlTagObject[], favicon?: string) => { export class HtmlBasicPlugin { readonly name: string; - readonly environment: EnvironmentContext; + readonly getEnvironment: () => EnvironmentContext; readonly options: HtmlBasicPluginOptions; @@ -248,7 +248,7 @@ export class HtmlBasicPlugin { modifyTagsFn?: ModifyHTMLTagsFn, ) { this.name = 'HtmlBasicPlugin'; - this.environment = environment; + this.getEnvironment = () => environment; this.options = options; this.modifyTagsFn = modifyTagsFn; } @@ -284,7 +284,7 @@ export class HtmlBasicPlugin { compilation, assetPrefix: data.publicPath, filename: data.outputName, - environment: this.environment, + environment: this.getEnvironment(), }) : tags; diff --git a/packages/core/tests/__snapshots__/builder.test.ts.snap b/packages/core/tests/__snapshots__/builder.test.ts.snap index a24499cb16..8a76238d5b 100644 --- a/packages/core/tests/__snapshots__/builder.test.ts.snap +++ b/packages/core/tests/__snapshots__/builder.test.ts.snap @@ -408,141 +408,7 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": { - "browserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "distPath": "/dist", - "entry": { - "index": "src/index.js", - }, - "htmlPaths": { - "index": "index.html", - }, - "index": 0, - "name": "web", - "normalizedConfig": { - "dev": { - "assetPrefix": "/", - "client": { - "host": "", - "overlay": true, - "path": "/rsbuild-hmr", - "port": "", - }, - "hmr": true, - "lazyCompilation": undefined, - "liveReload": true, - "writeToDisk": false, - }, - "html": { - "crossorigin": false, - "inject": "head", - "meta": { - "charset": { - "charset": "UTF-8", - }, - "viewport": "width=device-width, initial-scale=1.0", - }, - "mountId": "root", - "outputStructure": "flat", - "scriptLoading": "defer", - "title": "Rsbuild App", - }, - "output": { - "assetPrefix": "/", - "charset": "ascii", - "cssModules": { - "auto": true, - "exportGlobals": false, - "exportLocalsConvention": "camelCase", - "namedExport": false, - }, - "dataUriLimit": { - "font": 4096, - "image": 4096, - "media": 4096, - "svg": 4096, - }, - "distPath": { - "css": "static/css", - "font": "static/font", - "html": "/", - "image": "static/image", - "js": "static/js", - "media": "static/media", - "root": "dist", - "svg": "static/svg", - "wasm": "static/wasm", - }, - "emitAssets": true, - "filename": {}, - "filenameHash": true, - "injectStyles": false, - "inlineScripts": false, - "inlineStyles": false, - "legalComments": "linked", - "manifest": false, - "minify": true, - "polyfill": "usage", - "sourceMap": { - "css": false, - "js": undefined, - }, - "target": "web", - }, - "performance": { - "buildCache": true, - "chunkSplit": { - "strategy": "split-by-experience", - }, - "printFileSize": true, - "profile": false, - "removeConsole": false, - "removeMomentLocale": false, - }, - "security": { - "nonce": "", - "sri": { - "enable": false, - }, - }, - "server": { - "compress": true, - "host": "0.0.0.0", - "htmlFallback": "index", - "open": false, - "port": 3000, - "printUrls": true, - "strictPort": false, - }, - "source": { - "alias": {}, - "aliasStrategy": "prefer-tsconfig", - "decorators": { - "version": "2022-03", - }, - "define": {}, - "entry": { - "index": "src/index.js", - }, - "preEntry": [], - }, - "tools": { - "cssExtract": { - "loaderOptions": {}, - "pluginOptions": { - "ignoreOrder": true, - }, - }, - }, - }, - "target": "web", - "tsconfigPath": undefined, - }, + "getEnvironment": [Function], "modifyTagsFn": [Function], "name": "HtmlBasicPlugin", "options": { diff --git a/packages/core/tests/__snapshots__/default.test.ts.snap b/packages/core/tests/__snapshots__/default.test.ts.snap index 6004e98a50..08a58ac80a 100644 --- a/packages/core/tests/__snapshots__/default.test.ts.snap +++ b/packages/core/tests/__snapshots__/default.test.ts.snap @@ -408,142 +408,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": { - "browserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "distPath": "/packages/core/tests/dist", - "entry": { - "index": "src/index.js", - }, - "htmlPaths": { - "index": "index.html", - }, - "index": 0, - "name": "web", - "normalizedConfig": { - "dev": { - "assetPrefix": "/", - "client": { - "host": "", - "overlay": true, - "path": "/rsbuild-hmr", - "port": "", - }, - "hmr": true, - "lazyCompilation": undefined, - "liveReload": true, - "writeToDisk": false, - }, - "html": { - "crossorigin": false, - "inject": "head", - "meta": { - "charset": { - "charset": "UTF-8", - }, - "viewport": "width=device-width, initial-scale=1.0", - }, - "mountId": "root", - "outputStructure": "flat", - "scriptLoading": "defer", - "title": "Rsbuild App", - }, - "output": { - "assetPrefix": "/", - "charset": "ascii", - "cssModules": { - "auto": true, - "exportGlobals": false, - "exportLocalsConvention": "camelCase", - "namedExport": false, - }, - "dataUriLimit": { - "font": 4096, - "image": 4096, - "media": 4096, - "svg": 4096, - }, - "distPath": { - "css": "static/css", - "font": "static/font", - "html": "/", - "image": "static/image", - "js": "static/js", - "media": "static/media", - "root": "dist", - "svg": "static/svg", - "wasm": "static/wasm", - }, - "emitAssets": true, - "filename": {}, - "filenameHash": true, - "injectStyles": false, - "inlineScripts": false, - "inlineStyles": false, - "legalComments": "linked", - "manifest": false, - "minify": true, - "polyfill": "usage", - "sourceMap": { - "css": false, - "js": undefined, - }, - "target": "web", - }, - "performance": { - "buildCache": true, - "chunkSplit": { - "strategy": "split-by-experience", - }, - "printFileSize": true, - "profile": false, - "removeConsole": false, - "removeMomentLocale": false, - }, - "security": { - "nonce": "", - "sri": { - "enable": false, - }, - }, - "server": { - "compress": true, - "host": "0.0.0.0", - "htmlFallback": "index", - "open": false, - "port": 3000, - "printUrls": true, - "strictPort": false, - }, - "source": { - "alias": {}, - "aliasStrategy": "prefer-tsconfig", - "decorators": { - "version": "2022-03", - }, - "define": {}, - "entry": { - "index": "src/index.js", - }, - "preEntry": [], - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, - "tools": { - "cssExtract": { - "loaderOptions": {}, - "pluginOptions": { - "ignoreOrder": true, - }, - }, - }, - }, - "target": "web", - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, + "getEnvironment": [Function], "modifyTagsFn": [Function], "name": "HtmlBasicPlugin", "options": { @@ -1054,142 +919,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod "version": 5, }, HtmlBasicPlugin { - "environment": { - "browserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "distPath": "/packages/core/tests/dist", - "entry": { - "index": "src/index.js", - }, - "htmlPaths": { - "index": "index.html", - }, - "index": 0, - "name": "web", - "normalizedConfig": { - "dev": { - "assetPrefix": "/", - "client": { - "host": "", - "overlay": true, - "path": "/rsbuild-hmr", - "port": "", - }, - "hmr": true, - "lazyCompilation": undefined, - "liveReload": true, - "writeToDisk": false, - }, - "html": { - "crossorigin": false, - "inject": "head", - "meta": { - "charset": { - "charset": "UTF-8", - }, - "viewport": "width=device-width, initial-scale=1.0", - }, - "mountId": "root", - "outputStructure": "flat", - "scriptLoading": "defer", - "title": "Rsbuild App", - }, - "output": { - "assetPrefix": "/", - "charset": "ascii", - "cssModules": { - "auto": true, - "exportGlobals": false, - "exportLocalsConvention": "camelCase", - "namedExport": false, - }, - "dataUriLimit": { - "font": 4096, - "image": 4096, - "media": 4096, - "svg": 4096, - }, - "distPath": { - "css": "static/css", - "font": "static/font", - "html": "/", - "image": "static/image", - "js": "static/js", - "media": "static/media", - "root": "dist", - "svg": "static/svg", - "wasm": "static/wasm", - }, - "emitAssets": true, - "filename": {}, - "filenameHash": true, - "injectStyles": false, - "inlineScripts": false, - "inlineStyles": false, - "legalComments": "linked", - "manifest": false, - "minify": true, - "polyfill": "usage", - "sourceMap": { - "css": false, - "js": undefined, - }, - "target": "web", - }, - "performance": { - "buildCache": true, - "chunkSplit": { - "strategy": "split-by-experience", - }, - "printFileSize": true, - "profile": false, - "removeConsole": false, - "removeMomentLocale": false, - }, - "security": { - "nonce": "", - "sri": { - "enable": false, - }, - }, - "server": { - "compress": true, - "host": "0.0.0.0", - "htmlFallback": "index", - "open": false, - "port": 3000, - "printUrls": true, - "strictPort": false, - }, - "source": { - "alias": {}, - "aliasStrategy": "prefer-tsconfig", - "decorators": { - "version": "2022-03", - }, - "define": {}, - "entry": { - "index": "src/index.js", - }, - "preEntry": [], - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, - "tools": { - "cssExtract": { - "loaderOptions": {}, - "pluginOptions": { - "ignoreOrder": true, - }, - }, - }, - }, - "target": "web", - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, + "getEnvironment": [Function], "modifyTagsFn": [Function], "name": "HtmlBasicPlugin", "options": { @@ -1973,143 +1703,7 @@ exports[`tools.rspack > should match snapshot 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": { - "browserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "distPath": "/packages/core/tests/dist", - "entry": { - "index": "src/index.js", - }, - "htmlPaths": { - "index": "index.html", - }, - "index": 0, - "name": "web", - "normalizedConfig": { - "dev": { - "assetPrefix": "/", - "client": { - "host": "", - "overlay": true, - "path": "/rsbuild-hmr", - "port": "", - }, - "hmr": true, - "lazyCompilation": undefined, - "liveReload": true, - "writeToDisk": false, - }, - "html": { - "crossorigin": false, - "inject": "head", - "meta": { - "charset": { - "charset": "UTF-8", - }, - "viewport": "width=device-width, initial-scale=1.0", - }, - "mountId": "root", - "outputStructure": "flat", - "scriptLoading": "defer", - "title": "Rsbuild App", - }, - "output": { - "assetPrefix": "/", - "charset": "ascii", - "cssModules": { - "auto": true, - "exportGlobals": false, - "exportLocalsConvention": "camelCase", - "namedExport": false, - }, - "dataUriLimit": { - "font": 4096, - "image": 4096, - "media": 4096, - "svg": 4096, - }, - "distPath": { - "css": "static/css", - "font": "static/font", - "html": "/", - "image": "static/image", - "js": "static/js", - "media": "static/media", - "root": "dist", - "svg": "static/svg", - "wasm": "static/wasm", - }, - "emitAssets": true, - "filename": {}, - "filenameHash": true, - "injectStyles": false, - "inlineScripts": false, - "inlineStyles": false, - "legalComments": "linked", - "manifest": false, - "minify": true, - "polyfill": "usage", - "sourceMap": { - "css": false, - "js": undefined, - }, - "target": "web", - }, - "performance": { - "buildCache": true, - "chunkSplit": { - "strategy": "split-by-experience", - }, - "printFileSize": true, - "profile": false, - "removeConsole": false, - "removeMomentLocale": false, - }, - "security": { - "nonce": "", - "sri": { - "enable": false, - }, - }, - "server": { - "compress": true, - "host": "0.0.0.0", - "htmlFallback": "index", - "open": false, - "port": 3000, - "printUrls": true, - "strictPort": false, - }, - "source": { - "alias": {}, - "aliasStrategy": "prefer-tsconfig", - "decorators": { - "version": "2022-03", - }, - "define": {}, - "entry": { - "index": "src/index.js", - }, - "preEntry": [], - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, - "tools": { - "cssExtract": { - "loaderOptions": {}, - "pluginOptions": { - "ignoreOrder": true, - }, - }, - "rspack": [Function], - }, - }, - "target": "web", - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, + "getEnvironment": [Function], "modifyTagsFn": [Function], "name": "HtmlBasicPlugin", "options": { diff --git a/packages/core/tests/__snapshots__/html.test.ts.snap b/packages/core/tests/__snapshots__/html.test.ts.snap index 398cb8fb7d..a62848c3ae 100644 --- a/packages/core/tests/__snapshots__/html.test.ts.snap +++ b/packages/core/tests/__snapshots__/html.test.ts.snap @@ -116,153 +116,7 @@ exports[`plugin-html > should allow to configure html.tags 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": { - "browserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "distPath": "/packages/core/tests/dist", - "entry": { - "foo": "src/foo.ts", - "main": "src/main.ts", - }, - "htmlPaths": { - "foo": "foo.html", - "main": "main.html", - }, - "index": 0, - "name": "web", - "normalizedConfig": { - "dev": { - "assetPrefix": "/", - "client": { - "host": "", - "overlay": true, - "path": "/rsbuild-hmr", - "port": "", - }, - "hmr": true, - "lazyCompilation": undefined, - "liveReload": true, - "writeToDisk": false, - }, - "html": { - "crossorigin": false, - "inject": "head", - "meta": { - "charset": { - "charset": "UTF-8", - }, - "viewport": "width=device-width, initial-scale=1.0", - }, - "mountId": "root", - "outputStructure": "flat", - "scriptLoading": "defer", - "tags": [ - { - "attrs": { - "src": "jq.js", - }, - "tag": "script", - }, - ], - "title": "Rsbuild App", - }, - "output": { - "assetPrefix": "/", - "charset": "ascii", - "cssModules": { - "auto": true, - "exportGlobals": false, - "exportLocalsConvention": "camelCase", - "namedExport": false, - }, - "dataUriLimit": { - "font": 4096, - "image": 4096, - "media": 4096, - "svg": 4096, - }, - "distPath": { - "css": "static/css", - "font": "static/font", - "html": "/", - "image": "static/image", - "js": "static/js", - "media": "static/media", - "root": "dist", - "svg": "static/svg", - "wasm": "static/wasm", - }, - "emitAssets": true, - "filename": {}, - "filenameHash": true, - "injectStyles": false, - "inlineScripts": false, - "inlineStyles": false, - "legalComments": "linked", - "manifest": false, - "minify": true, - "polyfill": "usage", - "sourceMap": { - "css": false, - "js": undefined, - }, - "target": "web", - }, - "performance": { - "buildCache": true, - "chunkSplit": { - "strategy": "split-by-experience", - }, - "printFileSize": true, - "profile": false, - "removeConsole": false, - "removeMomentLocale": false, - }, - "security": { - "nonce": "", - "sri": { - "enable": false, - }, - }, - "server": { - "compress": true, - "host": "0.0.0.0", - "htmlFallback": "index", - "open": false, - "port": 3000, - "printUrls": true, - "strictPort": false, - }, - "source": { - "alias": {}, - "aliasStrategy": "prefer-tsconfig", - "decorators": { - "version": "2022-03", - }, - "define": {}, - "entry": { - "foo": "src/foo.ts", - "main": "src/main.ts", - }, - "preEntry": [], - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, - "tools": { - "cssExtract": { - "loaderOptions": {}, - "pluginOptions": { - "ignoreOrder": true, - }, - }, - }, - }, - "target": "web", - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, + "getEnvironment": [Function], "modifyTagsFn": undefined, "name": "HtmlBasicPlugin", "options": { @@ -339,143 +193,7 @@ exports[`plugin-html > should allow to modify plugin options by tools.htmlPlugin "version": 5, }, HtmlBasicPlugin { - "environment": { - "browserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "distPath": "/packages/core/tests/dist", - "entry": { - "index": "src/index.js", - }, - "htmlPaths": { - "index": "index.html", - }, - "index": 0, - "name": "web", - "normalizedConfig": { - "dev": { - "assetPrefix": "/", - "client": { - "host": "", - "overlay": true, - "path": "/rsbuild-hmr", - "port": "", - }, - "hmr": true, - "lazyCompilation": undefined, - "liveReload": true, - "writeToDisk": false, - }, - "html": { - "crossorigin": false, - "inject": "head", - "meta": { - "charset": { - "charset": "UTF-8", - }, - "viewport": "width=device-width, initial-scale=1.0", - }, - "mountId": "root", - "outputStructure": "flat", - "scriptLoading": "defer", - "title": "Rsbuild App", - }, - "output": { - "assetPrefix": "/", - "charset": "ascii", - "cssModules": { - "auto": true, - "exportGlobals": false, - "exportLocalsConvention": "camelCase", - "namedExport": false, - }, - "dataUriLimit": { - "font": 4096, - "image": 4096, - "media": 4096, - "svg": 4096, - }, - "distPath": { - "css": "static/css", - "font": "static/font", - "html": "/", - "image": "static/image", - "js": "static/js", - "media": "static/media", - "root": "dist", - "svg": "static/svg", - "wasm": "static/wasm", - }, - "emitAssets": true, - "filename": {}, - "filenameHash": true, - "injectStyles": false, - "inlineScripts": false, - "inlineStyles": false, - "legalComments": "linked", - "manifest": false, - "minify": true, - "polyfill": "usage", - "sourceMap": { - "css": false, - "js": undefined, - }, - "target": "web", - }, - "performance": { - "buildCache": true, - "chunkSplit": { - "strategy": "split-by-experience", - }, - "printFileSize": true, - "profile": false, - "removeConsole": false, - "removeMomentLocale": false, - }, - "security": { - "nonce": "", - "sri": { - "enable": false, - }, - }, - "server": { - "compress": true, - "host": "0.0.0.0", - "htmlFallback": "index", - "open": false, - "port": 3000, - "printUrls": true, - "strictPort": false, - }, - "source": { - "alias": {}, - "aliasStrategy": "prefer-tsconfig", - "decorators": { - "version": "2022-03", - }, - "define": {}, - "entry": { - "index": "src/index.js", - }, - "preEntry": [], - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, - "tools": { - "cssExtract": { - "loaderOptions": {}, - "pluginOptions": { - "ignoreOrder": true, - }, - }, - "htmlPlugin": [Function], - }, - }, - "target": "web", - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, + "getEnvironment": [Function], "modifyTagsFn": undefined, "name": "HtmlBasicPlugin", "options": { @@ -548,143 +266,7 @@ exports[`plugin-html > should allow to set favicon by html.favicon option 1`] = "version": 5, }, HtmlBasicPlugin { - "environment": { - "browserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "distPath": "/packages/core/tests/dist", - "entry": { - "index": "src/index.js", - }, - "htmlPaths": { - "index": "index.html", - }, - "index": 0, - "name": "web", - "normalizedConfig": { - "dev": { - "assetPrefix": "/", - "client": { - "host": "", - "overlay": true, - "path": "/rsbuild-hmr", - "port": "", - }, - "hmr": true, - "lazyCompilation": undefined, - "liveReload": true, - "writeToDisk": false, - }, - "html": { - "crossorigin": false, - "favicon": "src/favicon.ico", - "inject": "head", - "meta": { - "charset": { - "charset": "UTF-8", - }, - "viewport": "width=device-width, initial-scale=1.0", - }, - "mountId": "root", - "outputStructure": "flat", - "scriptLoading": "defer", - "title": "Rsbuild App", - }, - "output": { - "assetPrefix": "/", - "charset": "ascii", - "cssModules": { - "auto": true, - "exportGlobals": false, - "exportLocalsConvention": "camelCase", - "namedExport": false, - }, - "dataUriLimit": { - "font": 4096, - "image": 4096, - "media": 4096, - "svg": 4096, - }, - "distPath": { - "css": "static/css", - "font": "static/font", - "html": "/", - "image": "static/image", - "js": "static/js", - "media": "static/media", - "root": "dist", - "svg": "static/svg", - "wasm": "static/wasm", - }, - "emitAssets": true, - "filename": {}, - "filenameHash": true, - "injectStyles": false, - "inlineScripts": false, - "inlineStyles": false, - "legalComments": "linked", - "manifest": false, - "minify": true, - "polyfill": "usage", - "sourceMap": { - "css": false, - "js": undefined, - }, - "target": "web", - }, - "performance": { - "buildCache": true, - "chunkSplit": { - "strategy": "split-by-experience", - }, - "printFileSize": true, - "profile": false, - "removeConsole": false, - "removeMomentLocale": false, - }, - "security": { - "nonce": "", - "sri": { - "enable": false, - }, - }, - "server": { - "compress": true, - "host": "0.0.0.0", - "htmlFallback": "index", - "open": false, - "port": 3000, - "printUrls": true, - "strictPort": false, - }, - "source": { - "alias": {}, - "aliasStrategy": "prefer-tsconfig", - "decorators": { - "version": "2022-03", - }, - "define": {}, - "entry": { - "index": "src/index.js", - }, - "preEntry": [], - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, - "tools": { - "cssExtract": { - "loaderOptions": {}, - "pluginOptions": { - "ignoreOrder": true, - }, - }, - }, - }, - "target": "web", - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, + "getEnvironment": [Function], "modifyTagsFn": undefined, "name": "HtmlBasicPlugin", "options": { @@ -756,142 +338,7 @@ exports[`plugin-html > should allow to set inject by html.inject option 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": { - "browserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "distPath": "/packages/core/tests/dist", - "entry": { - "index": "src/index.js", - }, - "htmlPaths": { - "index": "index.html", - }, - "index": 0, - "name": "web", - "normalizedConfig": { - "dev": { - "assetPrefix": "/", - "client": { - "host": "", - "overlay": true, - "path": "/rsbuild-hmr", - "port": "", - }, - "hmr": true, - "lazyCompilation": undefined, - "liveReload": true, - "writeToDisk": false, - }, - "html": { - "crossorigin": false, - "inject": "body", - "meta": { - "charset": { - "charset": "UTF-8", - }, - "viewport": "width=device-width, initial-scale=1.0", - }, - "mountId": "root", - "outputStructure": "flat", - "scriptLoading": "defer", - "title": "Rsbuild App", - }, - "output": { - "assetPrefix": "/", - "charset": "ascii", - "cssModules": { - "auto": true, - "exportGlobals": false, - "exportLocalsConvention": "camelCase", - "namedExport": false, - }, - "dataUriLimit": { - "font": 4096, - "image": 4096, - "media": 4096, - "svg": 4096, - }, - "distPath": { - "css": "static/css", - "font": "static/font", - "html": "/", - "image": "static/image", - "js": "static/js", - "media": "static/media", - "root": "dist", - "svg": "static/svg", - "wasm": "static/wasm", - }, - "emitAssets": true, - "filename": {}, - "filenameHash": true, - "injectStyles": false, - "inlineScripts": false, - "inlineStyles": false, - "legalComments": "linked", - "manifest": false, - "minify": true, - "polyfill": "usage", - "sourceMap": { - "css": false, - "js": undefined, - }, - "target": "web", - }, - "performance": { - "buildCache": true, - "chunkSplit": { - "strategy": "split-by-experience", - }, - "printFileSize": true, - "profile": false, - "removeConsole": false, - "removeMomentLocale": false, - }, - "security": { - "nonce": "", - "sri": { - "enable": false, - }, - }, - "server": { - "compress": true, - "host": "0.0.0.0", - "htmlFallback": "index", - "open": false, - "port": 3000, - "printUrls": true, - "strictPort": false, - }, - "source": { - "alias": {}, - "aliasStrategy": "prefer-tsconfig", - "decorators": { - "version": "2022-03", - }, - "define": {}, - "entry": { - "index": "src/index.js", - }, - "preEntry": [], - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, - "tools": { - "cssExtract": { - "loaderOptions": {}, - "pluginOptions": { - "ignoreOrder": true, - }, - }, - }, - }, - "target": "web", - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, + "getEnvironment": [Function], "modifyTagsFn": undefined, "name": "HtmlBasicPlugin", "options": { @@ -1001,142 +448,7 @@ exports[`plugin-html > should enable minify in production 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": { - "browserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "distPath": "/packages/core/tests/dist", - "entry": { - "index": "src/index.js", - }, - "htmlPaths": { - "index": "index.html", - }, - "index": 0, - "name": "web", - "normalizedConfig": { - "dev": { - "assetPrefix": "/", - "client": { - "host": "", - "overlay": true, - "path": "/rsbuild-hmr", - "port": "", - }, - "hmr": true, - "lazyCompilation": undefined, - "liveReload": true, - "writeToDisk": false, - }, - "html": { - "crossorigin": false, - "inject": "head", - "meta": { - "charset": { - "charset": "UTF-8", - }, - "viewport": "width=device-width, initial-scale=1.0", - }, - "mountId": "root", - "outputStructure": "flat", - "scriptLoading": "defer", - "title": "Rsbuild App", - }, - "output": { - "assetPrefix": "/", - "charset": "ascii", - "cssModules": { - "auto": true, - "exportGlobals": false, - "exportLocalsConvention": "camelCase", - "namedExport": false, - }, - "dataUriLimit": { - "font": 4096, - "image": 4096, - "media": 4096, - "svg": 4096, - }, - "distPath": { - "css": "static/css", - "font": "static/font", - "html": "/", - "image": "static/image", - "js": "static/js", - "media": "static/media", - "root": "dist", - "svg": "static/svg", - "wasm": "static/wasm", - }, - "emitAssets": true, - "filename": {}, - "filenameHash": true, - "injectStyles": false, - "inlineScripts": false, - "inlineStyles": false, - "legalComments": "linked", - "manifest": false, - "minify": true, - "polyfill": "usage", - "sourceMap": { - "css": false, - "js": undefined, - }, - "target": "web", - }, - "performance": { - "buildCache": true, - "chunkSplit": { - "strategy": "split-by-experience", - }, - "printFileSize": true, - "profile": false, - "removeConsole": false, - "removeMomentLocale": false, - }, - "security": { - "nonce": "", - "sri": { - "enable": false, - }, - }, - "server": { - "compress": true, - "host": "0.0.0.0", - "htmlFallback": "index", - "open": false, - "port": 3000, - "printUrls": true, - "strictPort": false, - }, - "source": { - "alias": {}, - "aliasStrategy": "prefer-tsconfig", - "decorators": { - "version": "2022-03", - }, - "define": {}, - "entry": { - "index": "src/index.js", - }, - "preEntry": [], - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, - "tools": { - "cssExtract": { - "loaderOptions": {}, - "pluginOptions": { - "ignoreOrder": true, - }, - }, - }, - }, - "target": "web", - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, + "getEnvironment": [Function], "modifyTagsFn": undefined, "name": "HtmlBasicPlugin", "options": { @@ -1208,142 +520,7 @@ exports[`plugin-html > should register html plugin correctly 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": { - "browserslist": [ - "chrome >= 87", - "edge >= 88", - "firefox >= 78", - "safari >= 14", - ], - "distPath": "/packages/core/tests/dist", - "entry": { - "index": "src/index.js", - }, - "htmlPaths": { - "index": "index.html", - }, - "index": 0, - "name": "web", - "normalizedConfig": { - "dev": { - "assetPrefix": "/", - "client": { - "host": "", - "overlay": true, - "path": "/rsbuild-hmr", - "port": "", - }, - "hmr": true, - "lazyCompilation": undefined, - "liveReload": true, - "writeToDisk": false, - }, - "html": { - "crossorigin": false, - "inject": "head", - "meta": { - "charset": { - "charset": "UTF-8", - }, - "viewport": "width=device-width, initial-scale=1.0", - }, - "mountId": "root", - "outputStructure": "flat", - "scriptLoading": "defer", - "title": "Rsbuild App", - }, - "output": { - "assetPrefix": "/", - "charset": "ascii", - "cssModules": { - "auto": true, - "exportGlobals": false, - "exportLocalsConvention": "camelCase", - "namedExport": false, - }, - "dataUriLimit": { - "font": 4096, - "image": 4096, - "media": 4096, - "svg": 4096, - }, - "distPath": { - "css": "static/css", - "font": "static/font", - "html": "/", - "image": "static/image", - "js": "static/js", - "media": "static/media", - "root": "dist", - "svg": "static/svg", - "wasm": "static/wasm", - }, - "emitAssets": true, - "filename": {}, - "filenameHash": true, - "injectStyles": false, - "inlineScripts": false, - "inlineStyles": false, - "legalComments": "linked", - "manifest": false, - "minify": true, - "polyfill": "usage", - "sourceMap": { - "css": false, - "js": undefined, - }, - "target": "web", - }, - "performance": { - "buildCache": true, - "chunkSplit": { - "strategy": "split-by-experience", - }, - "printFileSize": true, - "profile": false, - "removeConsole": false, - "removeMomentLocale": false, - }, - "security": { - "nonce": "", - "sri": { - "enable": false, - }, - }, - "server": { - "compress": true, - "host": "0.0.0.0", - "htmlFallback": "index", - "open": false, - "port": 3000, - "printUrls": true, - "strictPort": false, - }, - "source": { - "alias": {}, - "aliasStrategy": "prefer-tsconfig", - "decorators": { - "version": "2022-03", - }, - "define": {}, - "entry": { - "index": "src/index.js", - }, - "preEntry": [], - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, - "tools": { - "cssExtract": { - "loaderOptions": {}, - "pluginOptions": { - "ignoreOrder": true, - }, - }, - }, - }, - "target": "web", - "tsconfigPath": "/packages/core/tests/tsconfig.json", - }, + "getEnvironment": [Function], "modifyTagsFn": undefined, "name": "HtmlBasicPlugin", "options": { @@ -1415,146 +592,7 @@ exports[`plugin-html > should stop injecting