diff --git a/packages/compat/plugin-swc/src/minimizer.ts b/packages/compat/plugin-swc/src/minimizer.ts index b97ae79e69..20fecbe182 100644 --- a/packages/compat/plugin-swc/src/minimizer.ts +++ b/packages/compat/plugin-swc/src/minimizer.ts @@ -37,12 +37,12 @@ export class SwcMinimizerPlugin { constructor(options: { jsMinify?: boolean | JsMinifyOptions; cssMinify?: boolean | CssMinifyOptions; - rsbuildConfig: NormalizedEnvironmentConfig; + environmentConfig: NormalizedEnvironmentConfig; }) { this.minifyOptions = { jsMinify: options.jsMinify ? deepmerge( - this.getDefaultJsMinifyOptions(options.rsbuildConfig), + this.getDefaultJsMinifyOptions(options.environmentConfig), normalize(options.jsMinify, {}), ) : undefined, @@ -53,10 +53,10 @@ export class SwcMinimizerPlugin { } getDefaultJsMinifyOptions( - rsbuildConfig: NormalizedEnvironmentConfig, + environmentConfig: NormalizedEnvironmentConfig, ): JsMinifyOptions { const options = { - ...__internalHelper.getSwcMinimizerOptions(rsbuildConfig), + ...__internalHelper.getSwcMinimizerOptions(environmentConfig), mangle: true, }; diff --git a/packages/compat/plugin-swc/src/plugin.ts b/packages/compat/plugin-swc/src/plugin.ts index 9a45a3e98b..29ccde0e1b 100644 --- a/packages/compat/plugin-swc/src/plugin.ts +++ b/packages/compat/plugin-swc/src/plugin.ts @@ -36,14 +36,13 @@ export const pluginSwc = (options: PluginSwcOptions = {}): RsbuildPlugin => ({ order: 'pre', handler: async (chain, utils) => { const { CHAIN_ID, environment } = utils; - const rsbuildConfig = api.getNormalizedConfig({ environment }); + const { config: environmentConfig, browserslist } = environment; const { rootPath } = api.context; - const { browserslist } = api.context.environments[environment]; const swcConfigs = await applyPluginConfig( options, utils, - rsbuildConfig, + environmentConfig, rootPath, browserslist, ); @@ -56,7 +55,7 @@ export const pluginSwc = (options: PluginSwcOptions = {}): RsbuildPlugin => ({ applyScriptCondition({ rule: chain.module.rule(CHAIN_ID.RULE.JS), chain, - config: rsbuildConfig, + config: environmentConfig, context: api.context, includes: [], excludes: [], @@ -116,10 +115,10 @@ export const pluginSwc = (options: PluginSwcOptions = {}): RsbuildPlugin => ({ }); api.modifyBundlerChain((chain, { CHAIN_ID, isProd, environment }) => { - const rsbuildConfig = api.getNormalizedConfig({ environment }); + const environmentConfig = environment.config; - if (checkUseMinify(mainConfig, rsbuildConfig, isProd)) { - const { minify } = rsbuildConfig.output; + if (checkUseMinify(mainConfig, environmentConfig, isProd)) { + const { minify } = environmentConfig.output; const minifyJs = minify === true || (typeof minify === 'object' && minify.js); const minifyCss = @@ -131,7 +130,7 @@ export const pluginSwc = (options: PluginSwcOptions = {}): RsbuildPlugin => ({ .use(SwcMinimizerPlugin, [ { jsMinify: mainConfig.jsMinify ?? mainConfig.jsc?.minify ?? true, - rsbuildConfig, + environmentConfig, }, ]); } @@ -142,7 +141,7 @@ export const pluginSwc = (options: PluginSwcOptions = {}): RsbuildPlugin => ({ .use(SwcMinimizerPlugin, [ { cssMinify: minifyCss ? mainConfig.cssMinify ?? true : false, - rsbuildConfig, + environmentConfig, }, ]); } diff --git a/packages/compat/webpack/src/build.ts b/packages/compat/webpack/src/build.ts index b618d84d94..7e4b83e626 100644 --- a/packages/compat/webpack/src/build.ts +++ b/packages/compat/webpack/src/build.ts @@ -40,10 +40,15 @@ export const build = async ( let isFirstCompile = true; await context.hooks.onBeforeBuild.call({ bundlerConfigs: bundlerConfigs as RspackConfig[], + environments: context.environments, }); const onDone = async (stats: Stats | MultiStats) => { - const p = context.hooks.onAfterBuild.call({ isFirstCompile, stats }); + const p = context.hooks.onAfterBuild.call({ + isFirstCompile, + stats, + environments: context.environments, + }); isFirstCompile = false; await p; }; diff --git a/packages/compat/webpack/src/createCompiler.ts b/packages/compat/webpack/src/createCompiler.ts index e11dbbbcf3..177d736529 100644 --- a/packages/compat/webpack/src/createCompiler.ts +++ b/packages/compat/webpack/src/createCompiler.ts @@ -60,6 +60,7 @@ export async function createCompiler({ await context.hooks.onAfterCreateCompiler.call({ compiler, + environments: context.environments, }); logger.debug('create compiler done'); diff --git a/packages/compat/webpack/src/plugin.ts b/packages/compat/webpack/src/plugin.ts index e91d312f89..215ad14a06 100644 --- a/packages/compat/webpack/src/plugin.ts +++ b/packages/compat/webpack/src/plugin.ts @@ -61,8 +61,7 @@ export const pluginAdaptor = (): RsbuildPlugin => ({ setup(api) { api.modifyBundlerChain(async (chain, { CHAIN_ID, environment, target }) => { - const config = api.getNormalizedConfig({ environment }); - const { tsconfigPath } = api.context.environments[environment]; + const { config, tsconfigPath } = environment; if (tsconfigPath && config.source.aliasStrategy === 'prefer-tsconfig') { await applyTsConfigPathsPlugin({ @@ -80,7 +79,7 @@ export const pluginAdaptor = (): RsbuildPlugin => ({ const { ProgressPlugin } = await import('./progress/ProgressPlugin'); chain.plugin(CHAIN_ID.PLUGIN.PROGRESS).use(ProgressPlugin, [ { - id: environment, + id: environment.name, ...(progress === true ? {} : progress), }, ]); diff --git a/packages/compat/webpack/src/webpackConfig.ts b/packages/compat/webpack/src/webpackConfig.ts index 82a8e64ddf..56a5ffccd9 100644 --- a/packages/compat/webpack/src/webpackConfig.ts +++ b/packages/compat/webpack/src/webpackConfig.ts @@ -6,6 +6,7 @@ import { reduceConfigsWithContext, } from '@rsbuild/core'; import { + type EnvironmentContext, type ModifyWebpackChainUtils, type ModifyWebpackConfigUtils, castArray, @@ -68,7 +69,7 @@ async function modifyWebpackConfig( async function getChainUtils( target: RsbuildTarget, - environment: string, + environment: EnvironmentContext, ): Promise { const { default: webpack } = await import('webpack'); const nameMap = { @@ -142,7 +143,10 @@ export async function generateWebpackConfig({ target: RsbuildTarget; context: InternalContext; }): Promise { - const chainUtils = await getChainUtils(target, environment); + const chainUtils = await getChainUtils( + target, + context.environments[environment], + ); const { default: webpack } = await import('webpack'); const { BannerPlugin, diff --git a/packages/compat/webpack/tests/__snapshots__/default.test.ts.snap b/packages/compat/webpack/tests/__snapshots__/default.test.ts.snap index a22be8eb9f..d128bf1a3c 100644 --- a/packages/compat/webpack/tests/__snapshots__/default.test.ts.snap +++ b/packages/compat/webpack/tests/__snapshots__/default.test.ts.snap @@ -330,7 +330,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": "web", + "getEnvironment": [Function], "modifyTagsFn": [Function], "name": "HtmlBasicPlugin", "options": { @@ -761,7 +761,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when produ "version": 5, }, HtmlBasicPlugin { - "environment": "web", + "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 b344c86804..0d6f479c23 100644 --- a/packages/compat/webpack/tests/__snapshots__/webpackConfig.test.ts.snap +++ b/packages/compat/webpack/tests/__snapshots__/webpackConfig.test.ts.snap @@ -78,7 +78,7 @@ exports[`webpackConfig > should allow to append and prepend plugins 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": "web", + "getEnvironment": [Function], "modifyTagsFn": [Function], "name": "HtmlBasicPlugin", "options": { diff --git a/packages/core/src/createContext.ts b/packages/core/src/createContext.ts index 9b61e232fa..3759429b48 100644 --- a/packages/core/src/createContext.ts +++ b/packages/core/src/createContext.ts @@ -47,7 +47,6 @@ async function createContextByConfig( return { version: RSBUILD_VERSION, - environments: {}, rootPath, distPath: '', cachePath, @@ -129,12 +128,12 @@ const getEnvironmentHTMLPaths = ( }; export async function updateEnvironmentContext( - context: RsbuildContext, + context: InternalContext, configs: Record, ): Promise { context.environments ||= {}; - for (const [name, config] of Object.entries(configs)) { + for (const [index, [name, config]] of Object.entries(configs).entries()) { const tsconfigPath = config.source.tsconfigPath ? getAbsolutePath(context.rootPath, config.source.tsconfigPath) : undefined; @@ -148,17 +147,21 @@ export async function updateEnvironmentContext( const htmlPaths = getEnvironmentHTMLPaths(entry, config); context.environments[name] = { - target: config.output.target, + index, + name, distPath: getAbsoluteDistPath(context.rootPath, config), entry, browserslist, htmlPaths, tsconfigPath, + config, }; } } -export function updateContextByNormalizedConfig(context: RsbuildContext): void { +export function updateContextByNormalizedConfig( + context: InternalContext, +): void { // Try to get the parent dist path from all environments const distPaths = Object.values(context.environments).map( (item) => item.distPath, @@ -216,6 +219,7 @@ export async function createContext( return { ...context, + environments: {}, hooks: initHooks(), config: { ...rsbuildConfig }, originalConfig: userRsbuildConfig, diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 88865efcac..12173aba57 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -67,6 +67,7 @@ export type { RsbuildEntry, RsbuildTarget, RsbuildContext, + EnvironmentContext, InspectConfigResult, InspectConfigOptions, // Subtypes of Config diff --git a/packages/core/src/plugins/asset.ts b/packages/core/src/plugins/asset.ts index 5346262ddf..aa6e45de55 100644 --- a/packages/core/src/plugins/asset.ts +++ b/packages/core/src/plugins/asset.ts @@ -75,7 +75,7 @@ export const pluginAsset = (): RsbuildPlugin => ({ setup(api) { api.modifyBundlerChain((chain, { isProd, environment }) => { - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; const createAssetRule = ( assetType: 'image' | 'media' | 'font' | 'svg', diff --git a/packages/core/src/plugins/basic.ts b/packages/core/src/plugins/basic.ts index 47d12b4a3a..8c31ee071c 100644 --- a/packages/core/src/plugins/basic.ts +++ b/packages/core/src/plugins/basic.ts @@ -19,9 +19,9 @@ export const pluginBasic = (): RsbuildPlugin => ({ setup(api) { api.modifyBundlerChain( (chain, { env, isProd, target, bundler, environment, CHAIN_ID }) => { - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; - chain.name(environment); + chain.name(environment.name); chain.devtool(getJsSourceMap(config)); diff --git a/packages/core/src/plugins/bundleAnalyzer.ts b/packages/core/src/plugins/bundleAnalyzer.ts index 36cf471933..cf60b2fc39 100644 --- a/packages/core/src/plugins/bundleAnalyzer.ts +++ b/packages/core/src/plugins/bundleAnalyzer.ts @@ -42,7 +42,7 @@ export function pluginBundleAnalyzer(): RsbuildPlugin { }); api.modifyBundlerChain(async (chain, { CHAIN_ID, environment }) => { - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; if (!isUseAnalyzer(config)) { return; @@ -58,7 +58,7 @@ export function pluginBundleAnalyzer(): RsbuildPlugin { { analyzerMode: 'static', openAnalyzer: false, - reportFilename: `report-${environment}.html`, + reportFilename: `report-${environment.name}.html`, ...(config.performance.bundleAnalyze || {}), }, ]); diff --git a/packages/core/src/plugins/cache.ts b/packages/core/src/plugins/cache.ts index 7727ebbf19..77d2e11d25 100644 --- a/packages/core/src/plugins/cache.ts +++ b/packages/core/src/plugins/cache.ts @@ -1,7 +1,11 @@ import crypto from 'node:crypto'; import fs from 'node:fs'; import { isAbsolute, join } from 'node:path'; -import type { BuildCacheOptions, RsbuildContext } from '@rsbuild/shared'; +import type { + BuildCacheOptions, + EnvironmentContext, + RsbuildContext, +} from '@rsbuild/shared'; import { findExists, isFileExists } from '../helpers'; import type { NormalizedEnvironmentConfig, RsbuildPlugin } from '../types'; @@ -58,7 +62,7 @@ function getCacheDirectory( async function getBuildDependencies( context: Readonly, config: NormalizedEnvironmentConfig, - environment: string, + environmentContext: EnvironmentContext, ) { const rootPackageJson = join(context.rootPath, 'package.json'); const browserslistConfig = join(context.rootPath, '.browserslistrc'); @@ -68,7 +72,7 @@ async function getBuildDependencies( if (await isFileExists(rootPackageJson)) { buildDependencies.packageJson = [rootPackageJson]; } - const { tsconfigPath } = context.environments[environment]; + const { tsconfigPath } = environmentContext; if (tsconfigPath) { buildDependencies.tsconfig = [tsconfigPath]; @@ -105,7 +109,7 @@ export const pluginCache = (): RsbuildPlugin => ({ } api.modifyBundlerChain(async (chain, { environment, env }) => { - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; const { buildCache } = config.performance; if (buildCache === false) { @@ -132,8 +136,8 @@ export const pluginCache = (): RsbuildPlugin => ({ // The default cache name of webpack is '${name}-${env}', and the `name` is `default` by default. // We set cache name to avoid cache conflicts of different targets. name: useDigest - ? `${environment}-${env}-${getDigestHash(cacheConfig.cacheDigest!)}` - : `${environment}-${env}`, + ? `${environment.name}-${env}-${getDigestHash(cacheConfig.cacheDigest!)}` + : `${environment.name}-${env}`, type: 'filesystem', cacheDirectory, buildDependencies, diff --git a/packages/core/src/plugins/cleanOutput.ts b/packages/core/src/plugins/cleanOutput.ts index dd72fc9f2d..82f0f4cf5b 100644 --- a/packages/core/src/plugins/cleanOutput.ts +++ b/packages/core/src/plugins/cleanOutput.ts @@ -1,5 +1,5 @@ import { sep } from 'node:path'; -import { color } from '@rsbuild/shared'; +import { type EnvironmentContext, color } from '@rsbuild/shared'; import { emptyDir } from '../helpers'; import { logger } from '../logger'; import type { RsbuildPlugin } from '../types'; @@ -16,10 +16,9 @@ export const pluginCleanOutput = (): RsbuildPlugin => ({ name: 'rsbuild:clean-output', setup(api) { - const clean = async (environment: string) => { + const clean = async (environment: EnvironmentContext) => { const { rootPath } = api.context; - const config = api.getNormalizedConfig({ environment }); - const { distPath } = api.context.environments[environment]; + const { config, distPath } = environment; let { cleanDistPath } = config.output; @@ -44,23 +43,19 @@ export const pluginCleanOutput = (): RsbuildPlugin => ({ } }; - const cleanAll = async () => { - const distPaths = Object.entries(api.context.environments).reduce< - Array<{ - environmentName: string; - distPath: string; - }> - >((total, [environmentName, curr]) => { + const cleanAll = async (params: { + environments: Record; + }) => { + const environments = Object.values(params.environments).reduce< + Array + >((total, curr) => { if (!total.find((t) => t.distPath === curr.distPath)) { - total.push({ - environmentName, - distPath: curr.distPath, - }); + total.push(curr); } return total; }, []); - await Promise.all(distPaths.map((d) => clean(d.environmentName))); + await Promise.all(environments.map((e) => clean(e))); }; api.onBeforeBuild(cleanAll); diff --git a/packages/core/src/plugins/css.ts b/packages/core/src/plugins/css.ts index c603377361..df58ba6e93 100644 --- a/packages/core/src/plugins/css.ts +++ b/packages/core/src/plugins/css.ts @@ -246,7 +246,7 @@ async function applyCSSRule({ utils: ModifyChainUtils; importLoaders?: number; }) { - const { browserslist } = context.environments[environment]; + const { browserslist } = environment; // 1. Check user config const enableExtractCSS = isUseCssExtract(config, target); @@ -327,9 +327,7 @@ export const pluginCss = (): RsbuildPlugin => ({ order: 'pre', handler: async (chain, utils) => { const rule = chain.module.rule(utils.CHAIN_ID.RULE.CSS); - const config = api.getNormalizedConfig({ - environment: utils.environment, - }); + const { config } = utils.environment; rule.test(CSS_REGEX); await applyCSSRule({ rule, diff --git a/packages/core/src/plugins/define.ts b/packages/core/src/plugins/define.ts index 210d30ca17..d6dc1177ea 100644 --- a/packages/core/src/plugins/define.ts +++ b/packages/core/src/plugins/define.ts @@ -7,7 +7,7 @@ export const pluginDefine = (): RsbuildPlugin => ({ setup(api) { api.modifyBundlerChain((chain, { CHAIN_ID, bundler, environment }) => { - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; const builtinVars: Define = { 'process.env.NODE_ENV': JSON.stringify(getNodeEnv()), 'process.env.ASSET_PREFIX': JSON.stringify( diff --git a/packages/core/src/plugins/entry.ts b/packages/core/src/plugins/entry.ts index 85895a2594..40ed78db66 100644 --- a/packages/core/src/plugins/entry.ts +++ b/packages/core/src/plugins/entry.ts @@ -8,9 +8,8 @@ export const pluginEntry = (): RsbuildPlugin => ({ setup(api) { api.modifyBundlerChain(async (chain, { environment, isServer }) => { - const config = api.getNormalizedConfig({ environment }); + const { config, entry } = environment; const { preEntry } = config.source; - const { entry } = api.context.environments[environment]; const injectCoreJsEntry = config.output.polyfill === 'entry' && !isServer; diff --git a/packages/core/src/plugins/externals.ts b/packages/core/src/plugins/externals.ts index 383b134745..2f9831dc5a 100644 --- a/packages/core/src/plugins/externals.ts +++ b/packages/core/src/plugins/externals.ts @@ -5,7 +5,7 @@ export function pluginExternals(): RsbuildPlugin { name: 'rsbuild:externals', setup(api) { api.modifyBundlerChain((chain, { environment }) => { - const { externals } = api.getNormalizedConfig({ environment }).output; + const { externals } = environment.config.output; if (externals) { chain.externals(externals); } diff --git a/packages/core/src/plugins/fileSize.ts b/packages/core/src/plugins/fileSize.ts index b0e3e228f0..775bb0990f 100644 --- a/packages/core/src/plugins/fileSize.ts +++ b/packages/core/src/plugins/fileSize.ts @@ -192,39 +192,35 @@ export const pluginFileSize = (): RsbuildPlugin => ({ name: 'rsbuild:file-size', setup(api) { - api.onAfterBuild(async ({ stats }) => { + api.onAfterBuild(async ({ stats, environments }) => { if (!stats) { return; } const logs = await Promise.all( - Object.keys(api.context.environments).map( - async (environment, index) => { - const { printFileSize } = api.getNormalizedConfig({ - environment, - }).performance; - - const multiStats = 'stats' in stats ? stats.stats : [stats]; - - const printFileSizeConfig = - typeof printFileSize === 'boolean' - ? { - total: true, - detail: true, - } - : printFileSize; - - if (printFileSize) { - return printFileSizes( - printFileSizeConfig, - multiStats[index], - api.context.rootPath, - environment, - ); - } - return []; - }, - ), + Object.values(environments).map(async (environment, index) => { + const { printFileSize } = environment.config.performance; + + const multiStats = 'stats' in stats ? stats.stats : [stats]; + + const printFileSizeConfig = + typeof printFileSize === 'boolean' + ? { + total: true, + detail: true, + } + : printFileSize; + + if (printFileSize) { + return printFileSizes( + printFileSizeConfig, + multiStats[index], + api.context.rootPath, + environment.name, + ); + } + return []; + }), ).catch((err) => { logger.warn('Failed to print file size.'); logger.warn(err as Error); diff --git a/packages/core/src/plugins/html.ts b/packages/core/src/plugins/html.ts index 8404f6e2bf..a9758a45ec 100644 --- a/packages/core/src/plugins/html.ts +++ b/packages/core/src/plugins/html.ts @@ -11,7 +11,6 @@ import type { HtmlConfig, ModifyHTMLTagsFn, NormalizedEnvironmentConfig, - RsbuildPluginAPI, } from '@rsbuild/shared'; import type { EntryDescription } from '@rspack/core'; import { STATIC_PATH } from '../constants'; @@ -256,10 +255,8 @@ function getChunks( } const getTagConfig = ( - api: RsbuildPluginAPI, - environment: string, + config: NormalizedEnvironmentConfig, ): TagConfig | undefined => { - const config = api.getNormalizedConfig({ environment }); const tags = castArray(config.html.tags).filter(Boolean); // skip if options is empty. @@ -281,9 +278,9 @@ export const pluginHtml = (modifyTagsFn?: ModifyHTMLTagsFn): RsbuildPlugin => ({ setup(api) { api.modifyBundlerChain( async (chain, { HtmlPlugin, isProd, CHAIN_ID, environment }) => { - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; - const htmlPaths = api.getHTMLPaths({ environment }); + const htmlPaths = api.getHTMLPaths({ environment: environment.name }); if (Object.keys(htmlPaths).length === 0) { return; } @@ -343,7 +340,7 @@ export const pluginHtml = (modifyTagsFn?: ModifyHTMLTagsFn): RsbuildPlugin => ({ htmlInfo.templateContent = templateContent; } - const tagConfig = getTagConfig(api, environment); + const tagConfig = getTagConfig(environment.config); if (tagConfig) { htmlInfo.tagConfig = tagConfig; } @@ -417,7 +414,7 @@ export const pluginHtml = (modifyTagsFn?: ModifyHTMLTagsFn): RsbuildPlugin => ({ // ensure `crossorigin` and `nonce` can be applied to all tags order: 'post', handler: ({ headTags, bodyTags }, { environment }) => { - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; const { crossorigin } = config.html; const allTags = [...headTags, ...bodyTags]; diff --git a/packages/core/src/plugins/inlineChunk.ts b/packages/core/src/plugins/inlineChunk.ts index f8b83cfd41..419e760dbe 100644 --- a/packages/core/src/plugins/inlineChunk.ts +++ b/packages/core/src/plugins/inlineChunk.ts @@ -8,12 +8,12 @@ export const pluginInlineChunk = (): RsbuildPlugin => ({ setup(api) { api.modifyBundlerChain(async (chain, { CHAIN_ID, isDev, environment }) => { - const htmlPaths = api.getHTMLPaths({ environment }); + const htmlPaths = api.getHTMLPaths({ environment: environment.name }); if (Object.keys(htmlPaths).length === 0 || isDev) { return; } - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; const { InlineChunkHtmlPlugin } = await import( '../rspack/InlineChunkHtmlPlugin' ); diff --git a/packages/core/src/plugins/lazyCompilation.ts b/packages/core/src/plugins/lazyCompilation.ts index b524e673bc..db385cf5c1 100644 --- a/packages/core/src/plugins/lazyCompilation.ts +++ b/packages/core/src/plugins/lazyCompilation.ts @@ -9,7 +9,7 @@ export const pluginLazyCompilation = (): RsbuildPlugin => ({ return; } - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; const options = config.dev?.lazyCompilation; if (!options) { diff --git a/packages/core/src/plugins/manifest.ts b/packages/core/src/plugins/manifest.ts index e40f1b32c3..5f029bd5e2 100644 --- a/packages/core/src/plugins/manifest.ts +++ b/packages/core/src/plugins/manifest.ts @@ -146,7 +146,7 @@ export const pluginManifest = (): RsbuildPlugin => ({ api.modifyBundlerChain(async (chain, { CHAIN_ID, environment }) => { const { output: { manifest }, - } = api.getNormalizedConfig({ environment }); + } = environment.config; if (manifest === false) { return; @@ -156,7 +156,7 @@ export const pluginManifest = (): RsbuildPlugin => ({ typeof manifest === 'string' ? manifest : 'manifest.json'; const { RspackManifestPlugin } = await import('rspack-manifest-plugin'); - const htmlPaths = api.getHTMLPaths({ environment }); + const htmlPaths = api.getHTMLPaths({ environment: environment.name }); chain.plugin(CHAIN_ID.PLUGIN.MANIFEST).use(RspackManifestPlugin, [ { diff --git a/packages/core/src/plugins/minimize.ts b/packages/core/src/plugins/minimize.ts index 223876ecda..6e9fc69815 100644 --- a/packages/core/src/plugins/minimize.ts +++ b/packages/core/src/plugins/minimize.ts @@ -108,7 +108,7 @@ export const pluginMinimize = (): RsbuildPlugin => ({ } api.modifyBundlerChain(async (chain, { isProd, environment }) => { - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; const isMinimize = isProd && config.output.minify !== false; if (!isMinimize) { diff --git a/packages/core/src/plugins/moduleFederation.ts b/packages/core/src/plugins/moduleFederation.ts index cbb1112a20..647e144e52 100644 --- a/packages/core/src/plugins/moduleFederation.ts +++ b/packages/core/src/plugins/moduleFederation.ts @@ -107,7 +107,7 @@ export function pluginModuleFederation(): RsbuildPlugin { api.modifyBundlerChain( async (chain, { CHAIN_ID, target, environment }) => { - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; if (!config.moduleFederation?.options || target !== 'web') { return; diff --git a/packages/core/src/plugins/moment.ts b/packages/core/src/plugins/moment.ts index e43a1e3175..4ee6ee5dd8 100644 --- a/packages/core/src/plugins/moment.ts +++ b/packages/core/src/plugins/moment.ts @@ -5,7 +5,7 @@ export const pluginMoment = (): RsbuildPlugin => ({ setup(api) { api.modifyBundlerChain(async (chain, { environment, bundler }) => { - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; if (config.performance.removeMomentLocale) { // Moment.js includes a lots of locale data by default. diff --git a/packages/core/src/plugins/nonce.ts b/packages/core/src/plugins/nonce.ts index 2f8a227026..731581d612 100644 --- a/packages/core/src/plugins/nonce.ts +++ b/packages/core/src/plugins/nonce.ts @@ -5,14 +5,12 @@ export const pluginNonce = (): RsbuildPlugin => ({ name: 'rsbuild:nonce', setup(api) { - api.onAfterCreateCompiler(({ compiler }) => { - const nonces = Object.keys(api.context.environments).map( - (environment) => { - const { nonce } = api.getNormalizedConfig({ environment }).security; + api.onAfterCreateCompiler(({ compiler, environments }) => { + const nonces = Object.values(environments).map((environment) => { + const { nonce } = environment.config.security; - return nonce; - }, - ); + return nonce; + }); if (!nonces.some((nonce) => !!nonce)) { return; @@ -43,7 +41,7 @@ export const pluginNonce = (): RsbuildPlugin => ({ // ensure `nonce` can be applied to all tags order: 'post', handler: ({ headTags, bodyTags }, { environment }) => { - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; const { nonce } = config.security; const allTags = [...headTags, ...bodyTags]; diff --git a/packages/core/src/plugins/output.ts b/packages/core/src/plugins/output.ts index d341c7a8f7..939205fb14 100644 --- a/packages/core/src/plugins/output.ts +++ b/packages/core/src/plugins/output.ts @@ -58,8 +58,7 @@ export const pluginOutput = (): RsbuildPlugin => ({ setup(api) { api.modifyBundlerChain( async (chain, { CHAIN_ID, target, isProd, isServer, environment }) => { - const config = api.getNormalizedConfig({ environment }); - const { distPath } = api.context.environments[environment]; + const { distPath, config } = environment; const publicPath = getPublicPath({ config, diff --git a/packages/core/src/plugins/performance.ts b/packages/core/src/plugins/performance.ts index f748fbd72c..e45b2e84f8 100644 --- a/packages/core/src/plugins/performance.ts +++ b/packages/core/src/plugins/performance.ts @@ -41,7 +41,7 @@ export const pluginPerformance = (): RsbuildPlugin => ({ }); api.modifyBundlerChain((chain, { environment }) => { - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; const { profile } = config.performance; if (!profile) { return; diff --git a/packages/core/src/plugins/progress.ts b/packages/core/src/plugins/progress.ts index d2db06235a..a90ad19149 100644 --- a/packages/core/src/plugins/progress.ts +++ b/packages/core/src/plugins/progress.ts @@ -23,7 +23,9 @@ export const pluginProgress = (): RsbuildPlugin => ({ } const prefix = - options !== true && options.id !== undefined ? options.id : environment; + options !== true && options.id !== undefined + ? options.id + : environment.name; chain.plugin(CHAIN_ID.PLUGIN.PROGRESS).use(rspack.ProgressPlugin, [ { diff --git a/packages/core/src/plugins/resolve.ts b/packages/core/src/plugins/resolve.ts index ef7255b14a..fdb16327a2 100644 --- a/packages/core/src/plugins/resolve.ts +++ b/packages/core/src/plugins/resolve.ts @@ -88,7 +88,7 @@ export const pluginResolve = (): RsbuildPlugin => ({ api.modifyBundlerChain({ order: 'pre', handler: (chain, { environment, CHAIN_ID }) => { - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; applyExtensions({ chain }); @@ -104,8 +104,7 @@ export const pluginResolve = (): RsbuildPlugin => ({ }); api.modifyRspackConfig(async (rspackConfig, { environment }) => { - const { tsconfigPath } = api.context.environments[environment]; - const config = api.getNormalizedConfig({ environment }); + const { tsconfigPath, config } = environment; if (tsconfigPath && config.source.aliasStrategy === 'prefer-tsconfig') { rspackConfig.resolve ||= {}; diff --git a/packages/core/src/plugins/resourceHints.ts b/packages/core/src/plugins/resourceHints.ts index 26959bd594..e186cc61c7 100644 --- a/packages/core/src/plugins/resourceHints.ts +++ b/packages/core/src/plugins/resourceHints.ts @@ -22,7 +22,7 @@ export const pluginResourceHints = (): RsbuildPlugin => ({ setup(api) { api.modifyHTMLTags(({ headTags, bodyTags }, { environment }) => { - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; const { dnsPrefetch, preconnect } = config.performance; if (dnsPrefetch) { @@ -45,13 +45,13 @@ export const pluginResourceHints = (): RsbuildPlugin => ({ }); api.modifyBundlerChain(async (chain, { CHAIN_ID, environment }) => { - const htmlPaths = api.getHTMLPaths({ environment }); + const htmlPaths = api.getHTMLPaths({ environment: environment.name }); if (Object.keys(htmlPaths).length === 0) { return; } - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; const { performance: { preload, prefetch }, } = config; diff --git a/packages/core/src/plugins/splitChunks.ts b/packages/core/src/plugins/splitChunks.ts index f44e8d26eb..0b1ddde8c8 100644 --- a/packages/core/src/plugins/splitChunks.ts +++ b/packages/core/src/plugins/splitChunks.ts @@ -246,7 +246,7 @@ export const pluginSplitChunks = (): RsbuildPlugin => ({ return; } - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; const defaultConfig: Exclude = { // Optimize both `initial` and `async` chunks chunks: 'all', diff --git a/packages/core/src/plugins/sri.ts b/packages/core/src/plugins/sri.ts index 4ee3f8f77a..936b562472 100644 --- a/packages/core/src/plugins/sri.ts +++ b/packages/core/src/plugins/sri.ts @@ -1,6 +1,11 @@ import type { Buffer } from 'node:buffer'; import crypto from 'node:crypto'; -import type { Rspack, SriAlgorithm, SriOptions } from '@rsbuild/shared'; +import type { + EnvironmentContext, + Rspack, + SriAlgorithm, + SriOptions, +} from '@rsbuild/shared'; import { HTML_REGEX } from '../constants'; import { isProd, removeLeadingSlash } from '../helpers'; import { logger } from '../logger'; @@ -19,8 +24,8 @@ export const pluginSri = (): RsbuildPlugin => ({ setup(api) { const placeholder = 'RSBUILD_INTEGRITY_PLACEHOLDER:'; - const getAlgorithm = (environment: string) => { - const config = api.getNormalizedConfig({ environment }); + const getAlgorithm = (environment: EnvironmentContext) => { + const { config } = environment; const { sri } = config.security; const enable = sri.enable === 'auto' ? isProd() : sri.enable; @@ -187,7 +192,7 @@ export const pluginSri = (): RsbuildPlugin => ({ } api.modifyBundlerChain((chain, { environment }) => { - const htmlPaths = api.getHTMLPaths({ environment }); + const htmlPaths = api.getHTMLPaths({ environment: environment.name }); if (Object.keys(htmlPaths).length === 0) { return; diff --git a/packages/core/src/plugins/swc.ts b/packages/core/src/plugins/swc.ts index bbf1c42d17..500d257e90 100644 --- a/packages/core/src/plugins/swc.ts +++ b/packages/core/src/plugins/swc.ts @@ -54,7 +54,7 @@ export const pluginSwc = (): RsbuildPlugin => ({ api.modifyBundlerChain({ order: 'pre', handler: async (chain, { CHAIN_ID, target, environment }) => { - const config = api.getNormalizedConfig({ environment }); + const { config, browserslist } = environment; const rule = chain.module .rule(CHAIN_ID.RULE.JS) @@ -76,8 +76,6 @@ export const pluginSwc = (): RsbuildPlugin => ({ excludes: [], }); - const { browserslist } = api.context.environments[environment]; - const swcConfig = getDefaultSwcConfig(browserslist); applyTransformImport(swcConfig, config.source.transformImport); diff --git a/packages/core/src/plugins/target.ts b/packages/core/src/plugins/target.ts index 6a80a668fb..c1c1bef1fb 100644 --- a/packages/core/src/plugins/target.ts +++ b/packages/core/src/plugins/target.ts @@ -13,7 +13,7 @@ export const pluginTarget = (): RsbuildPlugin => ({ return; } - const { browserslist } = api.context.environments[environment]; + const { browserslist } = environment; const esVersion = browserslistToESVersion(browserslist); if (target === 'web-worker') { diff --git a/packages/core/src/plugins/wasm.ts b/packages/core/src/plugins/wasm.ts index 3d900bf999..965029a735 100644 --- a/packages/core/src/plugins/wasm.ts +++ b/packages/core/src/plugins/wasm.ts @@ -6,7 +6,7 @@ export const pluginWasm = (): RsbuildPlugin => ({ setup(api) { api.modifyBundlerChain(async (chain, { CHAIN_ID, environment }) => { - const config = api.getNormalizedConfig({ environment }); + const { config } = environment; const distPath = config.output.distPath.wasm; chain.experiments({ diff --git a/packages/core/src/provider/build.ts b/packages/core/src/provider/build.ts index 8d8375ee52..e066ccdc8f 100644 --- a/packages/core/src/provider/build.ts +++ b/packages/core/src/provider/build.ts @@ -38,10 +38,15 @@ export const build = async ( let isFirstCompile = true; await context.hooks.onBeforeBuild.call({ bundlerConfigs, + environments: context.environments, }); const onDone = async (stats: Stats | MultiStats) => { - const p = context.hooks.onAfterBuild.call({ isFirstCompile, stats }); + const p = context.hooks.onAfterBuild.call({ + isFirstCompile, + stats, + environments: context.environments, + }); isFirstCompile = false; await p; }; diff --git a/packages/core/src/provider/createCompiler.ts b/packages/core/src/provider/createCompiler.ts index fcbd727304..64a78c57c9 100644 --- a/packages/core/src/provider/createCompiler.ts +++ b/packages/core/src/provider/createCompiler.ts @@ -122,7 +122,10 @@ export async function createCompiler({ rspack.MultiStats, ); - await context.hooks.onAfterCreateCompiler.call({ compiler }); + await context.hooks.onAfterCreateCompiler.call({ + compiler, + environments: context.environments, + }); logger.debug('create compiler done'); return compiler; diff --git a/packages/core/src/provider/rspackConfig.ts b/packages/core/src/provider/rspackConfig.ts index 5eb4cb176d..51fe8a4c86 100644 --- a/packages/core/src/provider/rspackConfig.ts +++ b/packages/core/src/provider/rspackConfig.ts @@ -1,5 +1,6 @@ import { CHAIN_ID, + type EnvironmentContext, type ModifyChainUtils, type ModifyRspackConfigUtils, type RsbuildTarget, @@ -90,7 +91,7 @@ async function getConfigUtils( export function getChainUtils( target: RsbuildTarget, - environment: string, + environment: EnvironmentContext, ): ModifyChainUtils { const nodeEnv = getNodeEnv(); @@ -116,7 +117,7 @@ export async function generateRspackConfig({ target: RsbuildTarget; context: InternalContext; }): Promise { - const chainUtils = getChainUtils(target, environment); + const chainUtils = getChainUtils(target, context.environments[environment]); const { BannerPlugin, DefinePlugin, diff --git a/packages/core/src/rspack/HtmlBasicPlugin.ts b/packages/core/src/rspack/HtmlBasicPlugin.ts index 02c6efbc8b..84fc06a1a9 100644 --- a/packages/core/src/rspack/HtmlBasicPlugin.ts +++ b/packages/core/src/rspack/HtmlBasicPlugin.ts @@ -1,4 +1,5 @@ import type { + EnvironmentContext, HtmlBasicTag, HtmlTag, HtmlTagDescriptor, @@ -235,7 +236,7 @@ const addFavicon = (headTags: HtmlTagObject[], favicon?: string) => { export class HtmlBasicPlugin { readonly name: string; - readonly environment: string; + readonly getEnvironment: () => EnvironmentContext; readonly options: HtmlBasicPluginOptions; @@ -243,11 +244,11 @@ export class HtmlBasicPlugin { constructor( options: HtmlBasicPluginOptions, - environment: string, + environment: EnvironmentContext, modifyTagsFn?: ModifyHTMLTagsFn, ) { this.name = 'HtmlBasicPlugin'; - this.environment = environment; + this.getEnvironment = () => environment; this.options = options; this.modifyTagsFn = modifyTagsFn; } @@ -283,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/src/server/devServer.ts b/packages/core/src/server/devServer.ts index 7b6c2acebf..e339dbbf54 100644 --- a/packages/core/src/server/devServer.ts +++ b/packages/core/src/server/devServer.ts @@ -189,7 +189,9 @@ export async function createDevServer< const protocol = https ? 'https' : 'http'; const urls = getAddressUrls({ protocol, port, host }); - await options.context.hooks.onBeforeStartDevServer.call(); + await options.context.hooks.onBeforeStartDevServer.call({ + environments: options.context.environments, + }); if (runCompile) { options.context.hooks.onBeforeCreateCompiler.tap(() => { diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index c579daa417..b6df3c1fa6 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -3,6 +3,7 @@ import type { Bundler, CreateCompiler, CreateDevServerOptions, + EnvironmentContext, InspectConfigOptions, InspectConfigResult, NormalizedConfig, @@ -52,6 +53,8 @@ export type InternalContext = RsbuildContext & { normalizedConfig?: NormalizedConfig; /** The plugin API. */ pluginAPI?: RsbuildPluginAPI; + /** The environment context. */ + environments: Record; }; export type CreateRsbuildOptions = { diff --git a/packages/core/tests/__snapshots__/builder.test.ts.snap b/packages/core/tests/__snapshots__/builder.test.ts.snap index c401482c85..8a76238d5b 100644 --- a/packages/core/tests/__snapshots__/builder.test.ts.snap +++ b/packages/core/tests/__snapshots__/builder.test.ts.snap @@ -408,7 +408,7 @@ exports[`should use rspack as default bundler > apply rspack correctly 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": "web", + "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 fb51a914f2..08a58ac80a 100644 --- a/packages/core/tests/__snapshots__/default.test.ts.snap +++ b/packages/core/tests/__snapshots__/default.test.ts.snap @@ -408,7 +408,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": "web", + "getEnvironment": [Function], "modifyTagsFn": [Function], "name": "HtmlBasicPlugin", "options": { @@ -919,7 +919,7 @@ exports[`applyDefaultPlugins > should apply default plugins correctly when prod "version": 5, }, HtmlBasicPlugin { - "environment": "web", + "getEnvironment": [Function], "modifyTagsFn": [Function], "name": "HtmlBasicPlugin", "options": { @@ -1703,7 +1703,7 @@ exports[`tools.rspack > should match snapshot 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": "web", + "getEnvironment": [Function], "modifyTagsFn": [Function], "name": "HtmlBasicPlugin", "options": { diff --git a/packages/core/tests/__snapshots__/environments.test.ts.snap b/packages/core/tests/__snapshots__/environments.test.ts.snap index 8cb18cf8cf..fa63fe2339 100644 --- a/packages/core/tests/__snapshots__/environments.test.ts.snap +++ b/packages/core/tests/__snapshots__/environments.test.ts.snap @@ -6,10 +6,125 @@ exports[`environment config > should normalize context correctly 1`] = ` "browserslist": [ "node >= 16", ], + "config": { + "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": "dist1/server", + "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": "node", + }, + "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": {}, + "preEntry": [], + }, + "tools": { + "cssExtract": { + "loaderOptions": {}, + "pluginOptions": { + "ignoreOrder": true, + }, + }, + }, + }, "distPath": "/dist1/server", "entry": {}, "htmlPaths": {}, - "target": "node", + "index": 0, + "name": "ssr", "tsconfigPath": undefined, }, "web": { @@ -19,10 +134,125 @@ exports[`environment config > should normalize context correctly 1`] = ` "firefox >= 78", "safari >= 14", ], + "config": { + "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": "dist1", + "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": {}, + "preEntry": [], + }, + "tools": { + "cssExtract": { + "loaderOptions": {}, + "pluginOptions": { + "ignoreOrder": true, + }, + }, + }, + }, "distPath": "/dist1", "entry": {}, "htmlPaths": {}, - "target": "web", + "index": 1, + "name": "web", "tsconfigPath": undefined, }, } diff --git a/packages/core/tests/__snapshots__/html.test.ts.snap b/packages/core/tests/__snapshots__/html.test.ts.snap index 585406ea13..a62848c3ae 100644 --- a/packages/core/tests/__snapshots__/html.test.ts.snap +++ b/packages/core/tests/__snapshots__/html.test.ts.snap @@ -116,7 +116,7 @@ exports[`plugin-html > should allow to configure html.tags 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": "web", + "getEnvironment": [Function], "modifyTagsFn": undefined, "name": "HtmlBasicPlugin", "options": { @@ -193,7 +193,7 @@ exports[`plugin-html > should allow to modify plugin options by tools.htmlPlugin "version": 5, }, HtmlBasicPlugin { - "environment": "web", + "getEnvironment": [Function], "modifyTagsFn": undefined, "name": "HtmlBasicPlugin", "options": { @@ -266,7 +266,7 @@ exports[`plugin-html > should allow to set favicon by html.favicon option 1`] = "version": 5, }, HtmlBasicPlugin { - "environment": "web", + "getEnvironment": [Function], "modifyTagsFn": undefined, "name": "HtmlBasicPlugin", "options": { @@ -338,7 +338,7 @@ exports[`plugin-html > should allow to set inject by html.inject option 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": "web", + "getEnvironment": [Function], "modifyTagsFn": undefined, "name": "HtmlBasicPlugin", "options": { @@ -448,7 +448,7 @@ exports[`plugin-html > should enable minify in production 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": "web", + "getEnvironment": [Function], "modifyTagsFn": undefined, "name": "HtmlBasicPlugin", "options": { @@ -520,7 +520,7 @@ exports[`plugin-html > should register html plugin correctly 1`] = ` "version": 5, }, HtmlBasicPlugin { - "environment": "web", + "getEnvironment": [Function], "modifyTagsFn": undefined, "name": "HtmlBasicPlugin", "options": { @@ -592,7 +592,7 @@ exports[`plugin-html > should stop injecting