@modern-js/uni-builder 2.54.6 → 2.56.0

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.
Files changed (48) hide show
  1. package/README.md +13 -6
  2. package/dist/index.d.ts +3 -4
  3. package/dist/index.js +6 -0
  4. package/dist/rspack/index.js +7 -2
  5. package/dist/rspack/plugins/babel-post.d.ts +1 -1
  6. package/dist/rspack/plugins/babel-post.js +2 -2
  7. package/dist/shared/compatLegacyPlugin.js +3 -2
  8. package/dist/shared/devServer.d.ts +4 -3
  9. package/dist/shared/devServer.js +18 -8
  10. package/dist/shared/getCssSupport.js +1 -1
  11. package/dist/shared/manifest.d.ts +1 -1
  12. package/dist/shared/parseCommonConfig.js +34 -70
  13. package/dist/shared/plugins/antd.d.ts +1 -1
  14. package/dist/shared/plugins/antd.js +3 -8
  15. package/dist/shared/plugins/arco.d.ts +1 -1
  16. package/dist/shared/plugins/arco.js +6 -8
  17. package/dist/shared/plugins/devtools.d.ts +1 -1
  18. package/dist/shared/plugins/emitRouteFile.d.ts +1 -1
  19. package/dist/shared/plugins/emitRouteFile.js +13 -8
  20. package/dist/shared/plugins/environmentDefaults.d.ts +3 -0
  21. package/dist/shared/plugins/environmentDefaults.js +81 -0
  22. package/dist/shared/plugins/extensionPrefix.d.ts +1 -2
  23. package/dist/shared/plugins/fallback.js +13 -20
  24. package/dist/shared/plugins/frameworkConfig.js +12 -2
  25. package/dist/shared/plugins/htmlMinify.d.ts +2 -0
  26. package/dist/shared/plugins/htmlMinify.js +140 -0
  27. package/dist/shared/plugins/mainFields.d.ts +1 -2
  28. package/dist/shared/plugins/postcssLegacy.d.ts +1 -1
  29. package/dist/shared/plugins/postcssLegacy.js +9 -6
  30. package/dist/shared/plugins/runtimeChunk.js +2 -2
  31. package/dist/shared/plugins/splitChunk.js +22 -4
  32. package/dist/shared/utils.d.ts +23 -3
  33. package/dist/shared/utils.js +131 -9
  34. package/dist/types.d.ts +44 -12
  35. package/dist/webpack/ModuleScopePlugin.js +14 -4
  36. package/dist/webpack/index.js +7 -2
  37. package/dist/webpack/plugins/babel.d.ts +1 -1
  38. package/dist/webpack/plugins/babel.js +15 -17
  39. package/dist/webpack/plugins/lazyCompilation.d.ts +1 -2
  40. package/dist/webpack/plugins/minimize.d.ts +1 -1
  41. package/dist/webpack/plugins/minimize.js +5 -6
  42. package/dist/webpack/plugins/moduleScopes.d.ts +1 -2
  43. package/dist/webpack/plugins/react.js +3 -3
  44. package/dist/webpack/plugins/styledComponents.d.ts +1 -2
  45. package/dist/webpack/plugins/styledComponents.js +2 -2
  46. package/dist/webpack/plugins/tsLoader.d.ts +5 -2
  47. package/dist/webpack/plugins/tsLoader.js +9 -10
  48. package/package.json +36 -31
package/README.md CHANGED
@@ -1,19 +1,26 @@
1
1
  <p align="center">
2
- <a href="https://rsbuild.dev" target="blank"><img src="https://github.com/web-infra-dev/rsbuild/assets/7237365/84abc13e-b620-468f-a90b-dbf28e7e9427" alt="Rsbuild Logo" /></a>
2
+ <a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
3
3
  </p>
4
4
 
5
- # Rsbuild
5
+ <h1 align="center">Modern.js</h1>
6
6
 
7
- Unleash the power of Rspack with the out-of-the-box build tool.
7
+ <p align="center">
8
+ A Progressive React Framework for modern web development.
9
+ </p>
10
+
11
+ ## Getting Started
12
+
13
+ Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-start) to get started with Modern.js.
8
14
 
9
15
  ## Documentation
10
16
 
11
- https://rsbuild.dev/
17
+ - [English Documentation](https://modernjs.dev/en/)
18
+ - [中文文档](https://modernjs.dev)
12
19
 
13
20
  ## Contributing
14
21
 
15
- Please read the [Contributing Guide](https://github.com/web-infra-dev/rsbuild/blob/main/CONTRIBUTING.md).
22
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
16
23
 
17
24
  ## License
18
25
 
19
- Rsbuild is [MIT licensed](https://github.com/web-infra-dev/rsbuild/blob/main/LICENSE).
26
+ Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
package/dist/index.d.ts CHANGED
@@ -4,10 +4,9 @@ import type { CreateUniBuilderOptions } from './types';
4
4
  import HtmlWebpackPlugin from 'html-webpack-plugin';
5
5
  export { HtmlWebpackPlugin };
6
6
  export type { CreateUniBuilderOptions, UniBuilderInstance, UniBuilderWebpackInstance, };
7
- export type { RspackChain, RsbuildPlugin, ConfigChain, CopyPluginOptions, ChainIdentifier, NormalizedConfig, RspackConfig, CacheGroup, } from '@rsbuild/shared';
8
- export type { UniBuilderConfig, UniBuilderPlugin } from './types';
7
+ export type { UniBuilderConfig, UniBuilderPlugin, BundlerType, MetaOptions, Stats, MultiStats, RspackConfig, } from './types';
9
8
  export type { StartDevServerOptions } from './shared/devServer';
10
9
  export declare function createUniBuilder(options: CreateUniBuilderOptions): Promise<UniBuilderInstance>;
11
- export { logger, type Rspack, type RsbuildContext, type RsbuildConfig, } from '@rsbuild/core';
10
+ export { logger, type ConfigChain, type RsbuildPlugin, type ChainIdentifier, type RspackChain, type Rspack, type RsbuildContext, type RsbuildConfig, type RsbuildTarget, type NormalizedConfig, type CacheGroup, } from '@rsbuild/core';
12
11
  export type { webpack, WebpackConfig } from '@rsbuild/webpack';
13
- export { RUNTIME_CHUNK_NAME } from './shared/utils';
12
+ export { RUNTIME_CHUNK_NAME, SERVICE_WORKER_ENVIRONMENT_NAME, isHtmlDisabled, castArray, } from './shared/utils';
package/dist/index.js CHANGED
@@ -30,7 +30,10 @@ var src_exports = {};
30
30
  __export(src_exports, {
31
31
  HtmlWebpackPlugin: () => import_html_webpack_plugin.default,
32
32
  RUNTIME_CHUNK_NAME: () => import_utils.RUNTIME_CHUNK_NAME,
33
+ SERVICE_WORKER_ENVIRONMENT_NAME: () => import_utils.SERVICE_WORKER_ENVIRONMENT_NAME,
34
+ castArray: () => import_utils.castArray,
33
35
  createUniBuilder: () => createUniBuilder,
36
+ isHtmlDisabled: () => import_utils.isHtmlDisabled,
34
37
  logger: () => import_core.logger
35
38
  });
36
39
  module.exports = __toCommonJS(src_exports);
@@ -46,6 +49,9 @@ async function createUniBuilder(options) {
46
49
  0 && (module.exports = {
47
50
  HtmlWebpackPlugin,
48
51
  RUNTIME_CHUNK_NAME,
52
+ SERVICE_WORKER_ENVIRONMENT_NAME,
53
+ castArray,
49
54
  createUniBuilder,
55
+ isHtmlDisabled,
50
56
  logger
51
57
  });
@@ -35,6 +35,7 @@ module.exports = __toCommonJS(rspack_exports);
35
35
  var import_core = require("@rsbuild/core");
36
36
  var import_parseCommonConfig = require("../shared/parseCommonConfig");
37
37
  var import_compatLegacyPlugin = require("../shared/compatLegacyPlugin");
38
+ var import_utils = require("../shared/utils");
38
39
  async function parseConfig(uniBuilderConfig, options) {
39
40
  var _uniBuilderConfig_experiments, _uniBuilderConfig_tools, _uniBuilderConfig_tools1;
40
41
  const { rsbuildConfig, rsbuildPlugins } = await (0, import_parseCommonConfig.parseCommonConfig)(uniBuilderConfig, options);
@@ -50,9 +51,13 @@ async function parseConfig(uniBuilderConfig, options) {
50
51
  }), pluginBabelPost());
51
52
  }
52
53
  if (((_uniBuilderConfig_tools1 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools1 === void 0 ? void 0 : _uniBuilderConfig_tools1.styledComponents) !== false) {
53
- var _uniBuilderConfig_tools3;
54
+ var _uniBuilderConfig_tools3, _uniBuilderConfig_environments;
54
55
  const { pluginStyledComponents } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-styled-components")));
55
- rsbuildPlugins.push(pluginStyledComponents((_uniBuilderConfig_tools3 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools3 === void 0 ? void 0 : _uniBuilderConfig_tools3.styledComponents));
56
+ const options2 = ((_uniBuilderConfig_tools3 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools3 === void 0 ? void 0 : _uniBuilderConfig_tools3.styledComponents) || {};
57
+ if ((_uniBuilderConfig_environments = uniBuilderConfig.environments) === null || _uniBuilderConfig_environments === void 0 ? void 0 : _uniBuilderConfig_environments[import_utils.SERVICE_WORKER_ENVIRONMENT_NAME]) {
58
+ options2.ssr = true;
59
+ }
60
+ rsbuildPlugins.push(pluginStyledComponents(options2));
56
61
  }
57
62
  return {
58
63
  rsbuildConfig,
@@ -1,4 +1,4 @@
1
- import { type RsbuildPlugin } from '@rsbuild/shared';
1
+ import { type RsbuildPlugin } from '@rsbuild/core';
2
2
  /**
3
3
  * should not set babel-loader when babel config not modified
4
4
  */
@@ -37,10 +37,10 @@ const pluginBabelPost = () => ({
37
37
  name: "uni-builder:babel-post",
38
38
  setup(api) {
39
39
  api.modifyBundlerChain({
40
- handler: async (chain, { CHAIN_ID }) => {
40
+ handler: async (chain, { CHAIN_ID, environment }) => {
41
41
  if (chain.module.rules.get(CHAIN_ID.RULE.JS)) {
42
42
  const { cacheIdentifier, ...babelLoaderOptions } = chain.module.rule(CHAIN_ID.RULE.JS).use(CHAIN_ID.USE.BABEL).get("options");
43
- const config = api.getNormalizedConfig();
43
+ const { config } = environment;
44
44
  if (babelLoaderOptions && (0, import_isEqual.default)((0, import_plugin_babel.getDefaultBabelOptions)(config, api.context), babelLoaderOptions)) {
45
45
  chain.module.rule(CHAIN_ID.RULE.JS).uses.delete(CHAIN_ID.USE.BABEL);
46
46
  }
@@ -34,14 +34,15 @@ function compatLegacyPlugin(plugin, extraInfo) {
34
34
  get(target, prop) {
35
35
  switch (prop) {
36
36
  case "target":
37
- addDeprecatedWarning(plugin.name, "context.target", "context.targets");
38
- return target.targets;
37
+ throw new Error(`Plugin(${plugin.name})'s api 'target' is deprecated, please use 'environment.config.output.target' instead.`);
39
38
  case "srcPath":
40
39
  addDeprecatedWarning(plugin.name, "context.srcPath");
41
40
  return (0, import_path.join)(extraInfo.cwd, "src");
42
41
  case "framework":
43
42
  addDeprecatedWarning(plugin.name, "context.framework");
44
43
  return "";
44
+ case "entry":
45
+ throw new Error(`Plugin(${plugin.name})'s api 'entry' is deprecated, please use 'environment.entry' instead.`);
45
46
  default: {
46
47
  if (prop in target) {
47
48
  return target[prop];
@@ -1,6 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { StartDevServerOptions as RsbuildStartDevServerOptions, DevConfig, ServerConfig } from '@rsbuild/shared';
3
- import { type RsbuildInstance } from '@rsbuild/core';
2
+ import { type RsbuildInstance, type DevConfig, type ServerConfig, type Rspack } from '@rsbuild/core';
4
3
  import type { ModernDevServerOptions } from '@modern-js/server';
5
4
  import type { Server } from 'node:http';
6
5
  import { type ApplyPlugins } from '@modern-js/prod-server';
@@ -12,7 +11,9 @@ export declare const transformToRsbuildServerOptions: (dev: NonNullable<UniBuild
12
11
  dev: DevConfig;
13
12
  server: ServerConfig;
14
13
  };
15
- export type StartDevServerOptions = RsbuildStartDevServerOptions & {
14
+ export type StartDevServerOptions = {
15
+ compiler?: Rspack.Compiler | Rspack.MultiCompiler;
16
+ getPortSilently?: boolean;
16
17
  apiOnly?: boolean;
17
18
  serverOptions?: ServerOptions;
18
19
  applyPlugins?: ApplyPlugins;
@@ -32,7 +32,7 @@ __export(devServer_exports, {
32
32
  transformToRsbuildServerOptions: () => transformToRsbuildServerOptions
33
33
  });
34
34
  module.exports = __toCommonJS(devServer_exports);
35
- var import_shared = require("@rsbuild/shared");
35
+ var import_ts_deepmerge = require("ts-deepmerge");
36
36
  var import_utils = require("@modern-js/utils");
37
37
  var import_core = require("@rsbuild/core");
38
38
  var import_prod_server = require("@modern-js/prod-server");
@@ -60,7 +60,7 @@ const getServerOptions = (builderConfig) => {
60
60
  };
61
61
  const transformToRsbuildServerOptions = (dev, devServer) => {
62
62
  var _newDevServerConfig_devMiddleware, _newDevServerConfig_before, _newDevServerConfig_after;
63
- const { port = 8080, host, https, ...devConfig } = dev;
63
+ const { port = 8080, host, https, startUrl, beforeStartUrl, ...devConfig } = dev;
64
64
  var _dev_hmr;
65
65
  const newDevServerConfig = (0, import_utils.applyOptionsChain)({
66
66
  devMiddleware: {
@@ -71,15 +71,19 @@ const transformToRsbuildServerOptions = (dev, devServer) => {
71
71
  client: {
72
72
  path: "/webpack-hmr",
73
73
  overlay: false,
74
+ port: "<port>",
74
75
  ...devConfig.client || {}
75
76
  }
76
- }, devServer, {}, import_shared.deepmerge);
77
+ }, devServer, {}, import_ts_deepmerge.merge);
77
78
  const rsbuildDev = {
78
- ...devConfig,
79
79
  writeToDisk: (_newDevServerConfig_devMiddleware = newDevServerConfig.devMiddleware) === null || _newDevServerConfig_devMiddleware === void 0 ? void 0 : _newDevServerConfig_devMiddleware.writeToDisk,
80
80
  hmr: newDevServerConfig.hot,
81
- client: newDevServerConfig.client,
82
- liveReload: newDevServerConfig.liveReload
81
+ liveReload: newDevServerConfig.liveReload,
82
+ ...devConfig,
83
+ client: {
84
+ ...newDevServerConfig.client,
85
+ ...devConfig.client || {}
86
+ }
83
87
  };
84
88
  if (dev.progressBar === void 0) {
85
89
  rsbuildDev.progressBar = true;
@@ -95,7 +99,7 @@ const transformToRsbuildServerOptions = (dev, devServer) => {
95
99
  } else if (newDevServerConfig.setupMiddlewares) {
96
100
  rsbuildDev.setupMiddlewares = newDevServerConfig.setupMiddlewares;
97
101
  }
98
- const server = (0, import_shared.isProd)() ? {
102
+ const server = (0, import_utils.isProd)() ? {
99
103
  publicDir: false,
100
104
  htmlFallback: false,
101
105
  printUrls: false
@@ -111,6 +115,12 @@ const transformToRsbuildServerOptions = (dev, devServer) => {
111
115
  host,
112
116
  https: https ? https : void 0
113
117
  };
118
+ if (!(0, import_utils.isProd)() && startUrl) {
119
+ server.open = beforeStartUrl ? {
120
+ target: startUrl === true ? "//localhost:<port>" : startUrl,
121
+ before: beforeStartUrl
122
+ } : startUrl;
123
+ }
114
124
  return {
115
125
  dev: rsbuildDev,
116
126
  server
@@ -118,7 +128,7 @@ const transformToRsbuildServerOptions = (dev, devServer) => {
118
128
  };
119
129
  const getDevServerOptions = async ({ builderConfig, serverOptions }) => {
120
130
  const defaultConfig = getServerOptions(builderConfig);
121
- const config = serverOptions.config ? (0, import_shared.deepmerge)(defaultConfig, serverOptions.config) : defaultConfig;
131
+ const config = serverOptions.config ? (0, import_ts_deepmerge.merge)(defaultConfig, serverOptions.config) : defaultConfig;
122
132
  return {
123
133
  config
124
134
  };
@@ -31,7 +31,7 @@ __export(getCssSupport_exports, {
31
31
  getCssSupport: () => getCssSupport
32
32
  });
33
33
  module.exports = __toCommonJS(getCssSupport_exports);
34
- var import_browserslist = __toESM(require("@rsbuild/shared/browserslist"));
34
+ var import_browserslist = __toESM(require("browserslist"));
35
35
  const CSS_FEATURES_BROWSER = {
36
36
  customProperties: {
37
37
  and_chr: "49",
@@ -1,4 +1,4 @@
1
- import type { Rspack } from '@rsbuild/shared';
1
+ import type { Rspack } from '@rsbuild/core';
2
2
  export declare const generateManifest: (seed: Record<string, any>, files: Array<{
3
3
  chunk?: Rspack.Chunk;
4
4
  name: string;
@@ -32,8 +32,8 @@ __export(parseCommonConfig_exports, {
32
32
  parseCommonConfig: () => parseCommonConfig
33
33
  });
34
34
  module.exports = __toCommonJS(parseCommonConfig_exports);
35
- var import_shared = require("@rsbuild/shared");
36
35
  var import_core = require("@rsbuild/core");
36
+ var import_utils = require("@modern-js/utils");
37
37
  var import_plugin_toml = require("@rsbuild/plugin-toml");
38
38
  var import_plugin_yaml = require("@rsbuild/plugin-yaml");
39
39
  var import_plugin_react = require("@rsbuild/plugin-react");
@@ -47,13 +47,16 @@ var import_devtools = require("./plugins/devtools");
47
47
  var import_emitRouteFile = require("./plugins/emitRouteFile");
48
48
  var import_antd = require("./plugins/antd");
49
49
  var import_arco = require("./plugins/arco");
50
+ var import_environmentDefaults = require("./plugins/environmentDefaults");
50
51
  var import_plugin_sass = require("@rsbuild/plugin-sass");
51
52
  var import_plugin_less = require("@rsbuild/plugin-less");
53
+ var import_htmlMinify = require("./plugins/htmlMinify");
52
54
  var import_devServer = require("./devServer");
55
+ var import_utils2 = require("./utils");
53
56
  const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
54
57
  const GLOBAL_CSS_REGEX = /\.global\.\w+$/;
55
58
  const isLooseCssModules = (path) => {
56
- if (import_shared.NODE_MODULES_REGEX.test(path)) {
59
+ if (import_utils2.NODE_MODULES_REGEX.test(path)) {
57
60
  return CSS_MODULES_REGEX.test(path);
58
61
  }
59
62
  return !GLOBAL_CSS_REGEX.test(path);
@@ -66,38 +69,6 @@ function removeUndefinedKey(obj) {
66
69
  });
67
70
  return obj;
68
71
  }
69
- const DEFAULT_WEB_BROWSERSLIST = [
70
- "> 0.01%",
71
- "not dead",
72
- "not op_mini all"
73
- ];
74
- const DEFAULT_BROWSERSLIST = {
75
- web: DEFAULT_WEB_BROWSERSLIST,
76
- node: [
77
- "node >= 14"
78
- ],
79
- "web-worker": DEFAULT_WEB_BROWSERSLIST,
80
- "service-worker": DEFAULT_WEB_BROWSERSLIST
81
- };
82
- async function getBrowserslistWithDefault(path, config, target) {
83
- const { overrideBrowserslist: overrides = {} } = (config === null || config === void 0 ? void 0 : config.output) || {};
84
- if (target === "web" || target === "web-worker") {
85
- if (Array.isArray(overrides)) {
86
- return overrides;
87
- }
88
- if (overrides[target]) {
89
- return overrides[target];
90
- }
91
- const browserslistrc = await (0, import_shared.getBrowserslist)(path);
92
- if (browserslistrc) {
93
- return browserslistrc;
94
- }
95
- }
96
- if (!Array.isArray(overrides) && overrides[target]) {
97
- return overrides[target];
98
- }
99
- return DEFAULT_BROWSERSLIST[target];
100
- }
101
72
  const isUseCssSourceMap = (disableSourceMap = {}) => {
102
73
  if (typeof disableSourceMap === "boolean") {
103
74
  return !disableSourceMap;
@@ -109,9 +80,9 @@ const isUseCssSourceMap = (disableSourceMap = {}) => {
109
80
  };
110
81
  async function parseCommonConfig(uniBuilderConfig, options) {
111
82
  var _uniBuilderConfig_output, _uniBuilderConfig_tools;
112
- var _output, _output_distPath, _output_distPath1, _output1, _extraConfig, _html, _extraConfig1;
113
- const { cwd, frameworkConfigPath, entry, target } = options;
114
- const { plugins: [...plugins] = [], performance: { ...performanceConfig } = {}, output: { disableFilenameHash, enableLatestDecorators, cssModuleLocalIdentName, enableInlineScripts, disableCssExtract, enableInlineStyles, enableCssModuleTSDeclaration, disableCssModuleExtension, disableTsChecker, disableSvgr, svgDefaultExport, assetsRetry, enableAssetFallback, enableAssetManifest, disableSourceMap, convertToRem, disableMinimize, polyfill, dataUriLimit = 1e4, ...outputConfig } = {}, html: { disableHtmlFolder, metaByEntries, titleByEntries, faviconByEntries, injectByEntries, templateByEntries, templateParametersByEntries, tagsByEntries, tags, ...htmlConfig } = {}, source: { alias, globalVars, resolveMainFields, resolveExtensionPrefix, ...sourceConfig } = {}, dev, security: { checkSyntax, sri, ...securityConfig } = {}, tools: { devServer, tsChecker, minifyCss, less, sass, ...toolsConfig } = {} } = uniBuilderConfig;
83
+ var _output_distPath, _output, _extraConfig, _html, _extraConfig1;
84
+ const { frameworkConfigPath } = options;
85
+ const { plugins: [...plugins] = [], performance: { ...performanceConfig } = {}, output: { disableFilenameHash, enableLatestDecorators, cssModuleLocalIdentName, enableInlineScripts, disableCssExtract, enableInlineStyles, enableCssModuleTSDeclaration, disableCssModuleExtension, disableTsChecker, disableSvgr, svgDefaultExport, assetsRetry, enableAssetFallback, enableAssetManifest, disableSourceMap, convertToRem, disableMinimize, polyfill, dataUriLimit = 1e4, distPath = {}, ...outputConfig } = {}, html: { disableHtmlFolder, metaByEntries, titleByEntries, faviconByEntries, injectByEntries, templateByEntries, templateParametersByEntries, tagsByEntries, tags, ...htmlConfig } = {}, source: { alias, globalVars, resolveMainFields, resolveExtensionPrefix, ...sourceConfig } = {}, dev, security: { checkSyntax, sri, ...securityConfig } = {}, tools: { devServer, tsChecker, minifyCss, less, sass, htmlPlugin, ...toolsConfig } = {}, environments = {} } = uniBuilderConfig;
115
86
  const rsbuildConfig = {
116
87
  plugins,
117
88
  output: {
@@ -126,39 +97,45 @@ async function parseCommonConfig(uniBuilderConfig, options) {
126
97
  performance: performanceConfig,
127
98
  html: htmlConfig,
128
99
  tools: toolsConfig,
129
- security: securityConfig
100
+ security: securityConfig,
101
+ environments
130
102
  };
103
+ rsbuildConfig.tools.htmlPlugin = htmlPlugin;
131
104
  const { html = {}, output = {}, source = {} } = rsbuildConfig;
132
105
  if (enableLatestDecorators) {
133
106
  source.decorators = {
134
107
  version: "2022-03"
135
108
  };
109
+ } else {
110
+ var _source;
111
+ var _decorators;
112
+ (_decorators = (_source = source).decorators) !== null && _decorators !== void 0 ? _decorators : _source.decorators = {
113
+ version: "legacy"
114
+ };
136
115
  }
137
116
  if (disableMinimize) {
138
- var _output2;
139
- (_output2 = output).minify || (_output2.minify = false);
117
+ var _output1;
118
+ (_output1 = output).minify || (_output1.minify = false);
140
119
  }
141
120
  if (cssModuleLocalIdentName) {
142
- var _output3;
143
- (_output3 = output).cssModules || (_output3.cssModules = {});
121
+ var _output2;
122
+ (_output2 = output).cssModules || (_output2.cssModules = {});
144
123
  output.cssModules.localIdentName = cssModuleLocalIdentName;
145
124
  }
146
125
  if (isUseCssSourceMap(disableSourceMap)) {
147
- var _output4;
148
- (_output4 = output).sourceMap || (_output4.sourceMap = {});
126
+ var _output3;
127
+ (_output3 = output).sourceMap || (_output3.sourceMap = {});
149
128
  output.sourceMap.css = true;
150
129
  }
151
- var _distPath;
152
- (_distPath = (_output = output).distPath) !== null && _distPath !== void 0 ? _distPath : _output.distPath = {};
130
+ const { server: _server, worker, ...rsbuildDistPath } = distPath;
131
+ output.distPath = rsbuildDistPath;
153
132
  var _html1;
154
133
  (_html1 = (_output_distPath = output.distPath).html) !== null && _html1 !== void 0 ? _html1 : _output_distPath.html = "html";
155
- var _server;
156
- (_server = (_output_distPath1 = output.distPath).server) !== null && _server !== void 0 ? _server : _output_distPath1.server = "bundles";
157
134
  var _polyfill;
158
- (_polyfill = (_output1 = output).polyfill) !== null && _polyfill !== void 0 ? _polyfill : _output1.polyfill = "entry";
135
+ (_polyfill = (_output = output).polyfill) !== null && _polyfill !== void 0 ? _polyfill : _output.polyfill = "entry";
159
136
  if (disableCssModuleExtension) {
160
- var _output5, _output_cssModules;
161
- (_output5 = output).cssModules || (_output5.cssModules = {});
137
+ var _output4, _output_cssModules;
138
+ (_output4 = output).cssModules || (_output4.cssModules = {});
162
139
  var _auto;
163
140
  (_auto = (_output_cssModules = output.cssModules).auto) !== null && _auto !== void 0 ? _auto : _output_cssModules.auto = isLooseCssModules;
164
141
  }
@@ -168,15 +145,6 @@ async function parseCommonConfig(uniBuilderConfig, options) {
168
145
  if (disableCssExtract) {
169
146
  output.injectStyles = disableCssExtract;
170
147
  }
171
- const targets = Array.isArray(target) ? target : [
172
- target || "web"
173
- ];
174
- output.targets = targets;
175
- const overrideBrowserslist = {};
176
- for (const target2 of targets) {
177
- overrideBrowserslist[target2] = await getBrowserslistWithDefault(cwd, uniBuilderConfig, target2);
178
- }
179
- output.overrideBrowserslist = overrideBrowserslist;
180
148
  if (enableInlineStyles) {
181
149
  output.inlineStyles = enableInlineStyles;
182
150
  }
@@ -215,10 +183,10 @@ async function parseCommonConfig(uniBuilderConfig, options) {
215
183
  if (tagsByEntries) {
216
184
  extraConfig.html.tags = [
217
185
  (tags2, utils) => {
218
- const entryTags = (0, import_shared.castArray)(tagsByEntries[utils.entryName]);
186
+ const entryTags = (0, import_utils2.castArray)(tagsByEntries[utils.entryName]);
219
187
  const handlers = [];
220
188
  for (const tag of entryTags) {
221
- if ((0, import_shared.isFunction)(tag)) {
189
+ if ((0, import_utils.isFunction)(tag)) {
222
190
  handlers.push(tag);
223
191
  } else {
224
192
  tags2.push(tag);
@@ -248,12 +216,6 @@ async function parseCommonConfig(uniBuilderConfig, options) {
248
216
  rsbuildConfig.dev = removeUndefinedKey(RsbuildDev);
249
217
  rsbuildConfig.html = html;
250
218
  rsbuildConfig.output = output;
251
- if (entry) {
252
- var _rsbuildConfig;
253
- var _source;
254
- (_source = (_rsbuildConfig = rsbuildConfig).source) !== null && _source !== void 0 ? _source : _rsbuildConfig.source = {};
255
- rsbuildConfig.source.entry = entry;
256
- }
257
219
  const rsbuildPlugins = [
258
220
  (0, import_splitChunk.pluginSplitChunks)(),
259
221
  (0, import_globalVars.pluginGlobalVars)(globalVars),
@@ -270,7 +232,9 @@ async function parseCommonConfig(uniBuilderConfig, options) {
270
232
  }),
271
233
  (0, import_plugin_less.pluginLess)({
272
234
  lessLoaderOptions: less
273
- })
235
+ }),
236
+ (0, import_environmentDefaults.pluginEnvironmentDefaults)(distPath),
237
+ (0, import_htmlMinify.pluginHtmlMinifierTerser)()
274
238
  ];
275
239
  if (checkSyntax) {
276
240
  const { pluginCheckSyntax } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-check-syntax")));
@@ -335,7 +299,7 @@ async function parseCommonConfig(uniBuilderConfig, options) {
335
299
  rsbuildPlugins.push((0, import_plugin_css_minimizer.pluginCssMinimizer)({
336
300
  pluginOptions: minifyCss
337
301
  }));
338
- targets.includes("web") && rsbuildPlugins.push((0, import_postcssLegacy.pluginPostcssLegacy)(overrideBrowserslist.web));
302
+ rsbuildPlugins.push((0, import_postcssLegacy.pluginPostcssLegacy)());
339
303
  if (enableAssetManifest) {
340
304
  const { pluginManifest } = await Promise.resolve().then(() => __toESM(require("./plugins/manifest")));
341
305
  rsbuildPlugins.push(pluginManifest());
@@ -1,2 +1,2 @@
1
- import { type RsbuildPlugin } from '@rsbuild/shared';
1
+ import { type RsbuildPlugin } from '@rsbuild/core';
2
2
  export declare const pluginAntd: () => RsbuildPlugin;
@@ -38,24 +38,19 @@ const getAntdMajorVersion = (appDirectory) => {
38
38
  const pluginAntd = () => ({
39
39
  name: "uni-builder:antd",
40
40
  setup(api) {
41
- api.modifyRsbuildConfig((rsbuildConfig) => {
41
+ api.modifyEnvironmentConfig((rsbuildConfig, { name }) => {
42
42
  var _rsbuildConfig_source_transformImport;
43
- var _rsbuildConfig;
44
- var _source;
45
- (_source = (_rsbuildConfig = rsbuildConfig).source) !== null && _source !== void 0 ? _source : _rsbuildConfig.source = {};
46
43
  if (rsbuildConfig.source.transformImport === false || ((_rsbuildConfig_source_transformImport = rsbuildConfig.source.transformImport) === null || _rsbuildConfig_source_transformImport === void 0 ? void 0 : _rsbuildConfig_source_transformImport.some((item) => item.libraryName === "antd"))) {
47
44
  return;
48
45
  }
46
+ const useServerEnvironment = (0, import_utils.isServerEnvironment)(rsbuildConfig.output.target, name);
49
47
  const antdMajorVersion = getAntdMajorVersion(api.context.rootPath);
50
48
  if (antdMajorVersion && antdMajorVersion < 5) {
51
- var _rsbuildConfig1;
52
- var _source1;
53
- (_source1 = (_rsbuildConfig1 = rsbuildConfig).source) !== null && _source1 !== void 0 ? _source1 : _rsbuildConfig1.source = {};
54
49
  rsbuildConfig.source.transformImport = [
55
50
  ...rsbuildConfig.source.transformImport || [],
56
51
  {
57
52
  libraryName: "antd",
58
- libraryDirectory: (0, import_utils.isServerTarget)(api.context.targets) ? "lib" : "es",
53
+ libraryDirectory: useServerEnvironment ? "lib" : "es",
59
54
  style: true
60
55
  }
61
56
  ];
@@ -1,2 +1,2 @@
1
- import { type RsbuildPlugin } from '@rsbuild/shared';
1
+ import { type RsbuildPlugin } from '@rsbuild/core';
2
2
  export declare const pluginArco: () => RsbuildPlugin;
@@ -22,23 +22,22 @@ __export(arco_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(arco_exports);
24
24
  var import_utils = require("@modern-js/utils");
25
- var import_utils2 = require("../../shared/utils");
25
+ var import_utils2 = require("../utils");
26
26
  const pluginArco = () => ({
27
27
  name: "uni-builder:arco",
28
28
  setup(api) {
29
29
  const ARCO_NAME = "@arco-design/web-react";
30
30
  const ARCO_ICON = `${ARCO_NAME}/icon`;
31
- api.modifyRsbuildConfig((rsbuildConfig) => {
32
- var _rsbuildConfig;
33
- const { transformImport = [] } = rsbuildConfig.source || {};
31
+ api.modifyEnvironmentConfig((rsbuildConfig, { name }) => {
32
+ const { transformImport = [] } = rsbuildConfig.source;
34
33
  if (transformImport === false || !(0, import_utils.isPackageInstalled)(ARCO_NAME, api.context.rootPath)) {
35
34
  return;
36
35
  }
37
- const isUseSSR = (0, import_utils2.isServerTarget)(api.context.targets);
36
+ const useServerEnvironment = (0, import_utils2.isServerEnvironment)(rsbuildConfig.output.target, name);
38
37
  if (!(transformImport === null || transformImport === void 0 ? void 0 : transformImport.some((item) => item.libraryName === ARCO_NAME))) {
39
38
  transformImport.push({
40
39
  libraryName: ARCO_NAME,
41
- libraryDirectory: isUseSSR ? "lib" : "es",
40
+ libraryDirectory: useServerEnvironment ? "lib" : "es",
42
41
  camelToDashComponentName: false,
43
42
  style: true
44
43
  });
@@ -46,11 +45,10 @@ const pluginArco = () => ({
46
45
  if (!(transformImport === null || transformImport === void 0 ? void 0 : transformImport.some((item) => item.libraryName === ARCO_ICON))) {
47
46
  transformImport.push({
48
47
  libraryName: ARCO_ICON,
49
- libraryDirectory: isUseSSR ? "react-icon-cjs" : "react-icon",
48
+ libraryDirectory: useServerEnvironment ? "react-icon-cjs" : "react-icon",
50
49
  camelToDashComponentName: false
51
50
  });
52
51
  }
53
- (_rsbuildConfig = rsbuildConfig).source || (_rsbuildConfig.source = {});
54
52
  rsbuildConfig.source.transformImport = transformImport;
55
53
  });
56
54
  }
@@ -1,4 +1,4 @@
1
- import { RsbuildPlugin } from '@rsbuild/shared';
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
2
  import { DisableSourceMapOption } from '../../types';
3
3
  export declare const pluginDevtool: (options: {
4
4
  disableSourceMap?: DisableSourceMapOption;
@@ -1,4 +1,4 @@
1
- import { type RsbuildPlugin } from '@rsbuild/shared';
1
+ import { type RsbuildPlugin } from '@rsbuild/core';
2
2
  export declare function isFileExists(file: string): Promise<boolean>;
3
3
  /**
4
4
  * generate a basic route.json for modern.js server
@@ -32,18 +32,23 @@ __export(emitRouteFile_exports, {
32
32
  pluginEmitRouteFile: () => pluginEmitRouteFile
33
33
  });
34
34
  module.exports = __toCommonJS(emitRouteFile_exports);
35
- var import_path = require("path");
36
- var import_shared = require("@rsbuild/shared");
35
+ var import_node_path = require("node:path");
36
+ var import_node_fs = __toESM(require("node:fs"));
37
37
  async function isFileExists(file) {
38
- return import_shared.fse.promises.access(file, import_shared.fse.constants.F_OK).then(() => true).catch(() => false);
38
+ return import_node_fs.default.promises.access(file, import_node_fs.default.constants.F_OK).then(() => true).catch(() => false);
39
39
  }
40
40
  const pluginEmitRouteFile = () => ({
41
41
  name: "uni-builder:emit-route-file",
42
42
  setup(api) {
43
- api.onBeforeStartDevServer(async () => {
44
- const { fs, ROUTE_SPEC_FILE } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
45
- const routeFilePath = (0, import_path.join)(api.context.distPath, ROUTE_SPEC_FILE);
46
- const htmlPaths = api.getHTMLPaths();
43
+ api.onBeforeStartDevServer(async ({ environments }) => {
44
+ const { fs: fs2, ROUTE_SPEC_FILE } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
45
+ const routeFilePath = (0, import_node_path.join)(api.context.distPath, ROUTE_SPEC_FILE);
46
+ const htmlPaths = Object.values(environments).reduce((prev, curr) => {
47
+ return {
48
+ ...prev,
49
+ ...curr.htmlPaths
50
+ };
51
+ }, {});
47
52
  const routesInfo = Object.entries(htmlPaths).map(([entryName, filename], index) => ({
48
53
  urlPath: index === 0 ? "/" : `/${entryName}`,
49
54
  entryName,
@@ -51,7 +56,7 @@ const pluginEmitRouteFile = () => ({
51
56
  isSPA: true
52
57
  }));
53
58
  if (!await isFileExists(routeFilePath) && routesInfo.length) {
54
- await fs.outputFile(routeFilePath, JSON.stringify({
59
+ await fs2.outputFile(routeFilePath, JSON.stringify({
55
60
  routes: routesInfo
56
61
  }, null, 2));
57
62
  }
@@ -0,0 +1,3 @@
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ import type { DistPath } from '../../types';
3
+ export declare const pluginEnvironmentDefaults: (distPath?: DistPath) => RsbuildPlugin;