@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
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var environmentDefaults_exports = {};
20
+ __export(environmentDefaults_exports, {
21
+ pluginEnvironmentDefaults: () => pluginEnvironmentDefaults
22
+ });
23
+ module.exports = __toCommonJS(environmentDefaults_exports);
24
+ var import_node_path = require("node:path");
25
+ var import_utils = require("../utils");
26
+ const pluginEnvironmentDefaults = (distPath = {}) => ({
27
+ name: "uni-builder:environment-defaults-plugin",
28
+ setup(api) {
29
+ api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {
30
+ var _config_environments, _config_environments1;
31
+ const compatConfig = {};
32
+ if ((_config_environments = config.environments) === null || _config_environments === void 0 ? void 0 : _config_environments[import_utils.SERVICE_WORKER_ENVIRONMENT_NAME]) {
33
+ var _compatConfig;
34
+ var _environments;
35
+ (_environments = (_compatConfig = compatConfig).environments) !== null && _environments !== void 0 ? _environments : _compatConfig.environments = {};
36
+ compatConfig.environments[import_utils.SERVICE_WORKER_ENVIRONMENT_NAME] = {
37
+ output: {
38
+ distPath: {
39
+ root: (0, import_node_path.join)(distPath.root || "dist", distPath.worker || "worker"),
40
+ js: "",
41
+ css: "",
42
+ jsAsync: "",
43
+ cssAsync: ""
44
+ },
45
+ filename: {
46
+ js: "[name].js"
47
+ }
48
+ }
49
+ };
50
+ }
51
+ if ((_config_environments1 = config.environments) === null || _config_environments1 === void 0 ? void 0 : _config_environments1.node) {
52
+ var _compatConfig1;
53
+ var _environments1;
54
+ (_environments1 = (_compatConfig1 = compatConfig).environments) !== null && _environments1 !== void 0 ? _environments1 : _compatConfig1.environments = {};
55
+ compatConfig.environments.node = {
56
+ output: {
57
+ // no need to emit assets for SSR bundles
58
+ emitAssets: false,
59
+ distPath: {
60
+ root: (0, import_node_path.join)(distPath.root || "dist", distPath.server || "bundles"),
61
+ js: "",
62
+ css: "",
63
+ jsAsync: "",
64
+ cssAsync: ""
65
+ }
66
+ }
67
+ };
68
+ }
69
+ return compatConfig.environments ? mergeRsbuildConfig(compatConfig, config) : config;
70
+ });
71
+ api.modifyEnvironmentConfig(async (config, { name }) => {
72
+ var _config_output;
73
+ var _overrideBrowserslist;
74
+ (_overrideBrowserslist = (_config_output = config.output).overrideBrowserslist) !== null && _overrideBrowserslist !== void 0 ? _overrideBrowserslist : _config_output.overrideBrowserslist = await (0, import_utils.getBrowserslistWithDefault)(api.context.rootPath, config, name === import_utils.SERVICE_WORKER_ENVIRONMENT_NAME ? "node" : config.output.target);
75
+ });
76
+ }
77
+ });
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
80
+ pluginEnvironmentDefaults
81
+ });
@@ -1,3 +1,2 @@
1
- import type { RsbuildPlugin } from '@rsbuild/core';
2
- import type { RsbuildTarget } from '@rsbuild/shared';
1
+ import type { RsbuildPlugin, RsbuildTarget } from '@rsbuild/core';
3
2
  export declare const pluginExtensionPrefix: (prefixInfo: string | Partial<Record<RsbuildTarget, string>>) => RsbuildPlugin;
@@ -22,7 +22,6 @@ __export(fallback_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(fallback_exports);
24
24
  var import_path = require("path");
25
- var import_shared = require("@rsbuild/shared");
26
25
  var import_utils = require("../../shared/utils");
27
26
  const HTML_REGEX = /\.html$/;
28
27
  const resourceRuleFallback = (rules = []) => {
@@ -50,7 +49,7 @@ const resourceRuleFallback = (rules = []) => {
50
49
  }
51
50
  const fileLoader = {
52
51
  exclude: [
53
- import_shared.JS_REGEX,
52
+ import_utils.JS_REGEX,
54
53
  import_utils.TS_REGEX,
55
54
  // exclude `html` and `json`, they get processed by webpack internal loaders.
56
55
  HTML_REGEX,
@@ -71,17 +70,17 @@ const resourceRuleFallback = (rules = []) => {
71
70
  const pluginFallback = () => ({
72
71
  name: "uni-builder:fallback",
73
72
  setup(api) {
74
- if (api.context.bundlerType === "webpack") {
75
- api.modifyBundlerChain((chain) => {
76
- const rsbuildConfig = api.getNormalizedConfig();
77
- const { distPath, filename } = rsbuildConfig.output;
78
- const distDir = distPath.media;
79
- var _filename_media;
80
- const mediaFilename = (_filename_media = filename.media) !== null && _filename_media !== void 0 ? _filename_media : `[name]${(0, import_utils.getHash)(rsbuildConfig)}[ext]`;
81
- chain.output.merge({
82
- assetModuleFilename: (0, import_path.join)(distDir, mediaFilename)
83
- });
73
+ api.modifyBundlerChain((chain, { environment }) => {
74
+ const rsbuildConfig = environment.config;
75
+ const { distPath, filename } = rsbuildConfig.output;
76
+ const distDir = distPath.media;
77
+ var _filename_media;
78
+ const mediaFilename = (_filename_media = filename.media) !== null && _filename_media !== void 0 ? _filename_media : `[name]${(0, import_utils.getHash)(rsbuildConfig)}[ext]`;
79
+ chain.output.merge({
80
+ assetModuleFilename: (0, import_path.join)(distDir, mediaFilename)
84
81
  });
82
+ });
83
+ if (api.context.bundlerType === "webpack") {
85
84
  api.modifyWebpackConfig((config) => {
86
85
  if (!config.module) {
87
86
  return;
@@ -91,17 +90,11 @@ const pluginFallback = () => ({
91
90
  } else {
92
91
  api.modifyRspackConfig((config) => {
93
92
  var _config_module;
94
- var _config, _config1;
95
- const rsbuildConfig = api.getNormalizedConfig();
96
- const distDir = rsbuildConfig.output.distPath.media;
97
- var _rsbuildConfig_output_filename_media;
98
- const filename = (_rsbuildConfig_output_filename_media = rsbuildConfig.output.filename.media) !== null && _rsbuildConfig_output_filename_media !== void 0 ? _rsbuildConfig_output_filename_media : `[name]${(0, import_utils.getHash)(rsbuildConfig)}[ext]`;
99
- (_config = config).output || (_config.output = {});
100
- config.output.assetModuleFilename = (0, import_path.join)(distDir, filename);
93
+ var _config;
101
94
  if (!config.module) {
102
95
  return;
103
96
  }
104
- (_config1 = config).module || (_config1.module = {});
97
+ (_config = config).module || (_config.module = {});
105
98
  config.module.rules = resourceRuleFallback((_config_module = config.module) === null || _config_module === void 0 ? void 0 : _config_module.rules);
106
99
  });
107
100
  }
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,18 +17,26 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var frameworkConfig_exports = {};
20
30
  __export(frameworkConfig_exports, {
21
31
  pluginFrameworkConfig: () => pluginFrameworkConfig
22
32
  });
23
33
  module.exports = __toCommonJS(frameworkConfig_exports);
24
- var import_shared = require("@rsbuild/shared");
34
+ var import_node_fs = __toESM(require("node:fs"));
25
35
  const pluginFrameworkConfig = (configPath) => ({
26
36
  name: "uni-builder:framework-config",
27
37
  setup(api) {
28
38
  api.modifyBundlerChain((chain) => {
29
- if (!import_shared.fse.existsSync(configPath)) {
39
+ if (!import_node_fs.default.existsSync(configPath)) {
30
40
  return;
31
41
  }
32
42
  const cache = chain.get("cache");
@@ -0,0 +1,2 @@
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ export declare const pluginHtmlMinifierTerser: () => RsbuildPlugin;
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var htmlMinify_exports = {};
30
+ __export(htmlMinify_exports, {
31
+ pluginHtmlMinifierTerser: () => pluginHtmlMinifierTerser
32
+ });
33
+ module.exports = __toCommonJS(htmlMinify_exports);
34
+ var import_ts_deepmerge = require("ts-deepmerge");
35
+ function applyRemoveConsole(options, config) {
36
+ const { removeConsole } = config.performance;
37
+ const compressOptions = typeof options.compress === "boolean" ? {} : options.compress || {};
38
+ if (removeConsole === true) {
39
+ options.compress = {
40
+ ...compressOptions,
41
+ drop_console: true
42
+ };
43
+ } else if (Array.isArray(removeConsole)) {
44
+ const pureFuncs = removeConsole.map((method) => `console.${method}`);
45
+ options.compress = {
46
+ ...compressOptions,
47
+ pure_funcs: pureFuncs
48
+ };
49
+ }
50
+ return options;
51
+ }
52
+ function getTerserMinifyOptions(config) {
53
+ const options = {
54
+ mangle: {
55
+ safari10: true
56
+ },
57
+ format: {
58
+ ascii_only: config.output.charset === "ascii"
59
+ }
60
+ };
61
+ if (config.output.legalComments === "none") {
62
+ var _options;
63
+ (_options = options).format || (_options.format = {});
64
+ options.format.comments = false;
65
+ }
66
+ const finalOptions = applyRemoveConsole(options, config);
67
+ return finalOptions;
68
+ }
69
+ function getMinifyOptions(config) {
70
+ const minifyJS = getTerserMinifyOptions(config);
71
+ return {
72
+ removeComments: false,
73
+ useShortDoctype: true,
74
+ keepClosingSlash: true,
75
+ collapseWhitespace: true,
76
+ removeRedundantAttributes: true,
77
+ removeScriptTypeAttributes: true,
78
+ removeStyleLinkTypeAttributes: true,
79
+ removeEmptyAttributes: true,
80
+ minifyJS,
81
+ minifyCSS: true,
82
+ minifyURLs: true
83
+ };
84
+ }
85
+ const pluginHtmlMinifierTerser = () => ({
86
+ name: "uni-builder:plugin-html-minifier-terser",
87
+ setup(api) {
88
+ api.modifyBundlerChain(async (chain, { isProd, environment }) => {
89
+ const { output, tools: { htmlPlugin } } = environment.config;
90
+ if (!isProd || output.minify === false || htmlPlugin === false) {
91
+ return;
92
+ }
93
+ const { minify } = await Promise.resolve().then(() => __toESM(require("html-minifier-terser")));
94
+ const pluginRecord = chain.plugins.entries();
95
+ const minifyOptions = getMinifyOptions(environment.config);
96
+ for (const id of Object.keys(pluginRecord)) {
97
+ if (!id.startsWith("html-")) {
98
+ continue;
99
+ }
100
+ const values = pluginRecord[id].values();
101
+ const isHtmlRspackPlugin = values.some((item) => {
102
+ var _item_constructor;
103
+ const name = (item === null || item === void 0 ? void 0 : item.name) || ((_item_constructor = item.constructor) === null || _item_constructor === void 0 ? void 0 : _item_constructor.name);
104
+ return name === "HtmlRspackPlugin";
105
+ });
106
+ if (isHtmlRspackPlugin) {
107
+ chain.plugin(id).tap((options) => {
108
+ if (!options.length) {
109
+ return options;
110
+ }
111
+ const userMinifyOption = options[0].minify;
112
+ const minifyFn = (html) => minify(html, userMinifyOption ? (0, import_ts_deepmerge.merge)(minifyOptions, userMinifyOption) : minifyOptions);
113
+ options[0].minify = minifyFn;
114
+ return options;
115
+ });
116
+ continue;
117
+ }
118
+ const isHtmlWebpackPlugin = values.some((item) => {
119
+ var _item_constructor;
120
+ const name = (item === null || item === void 0 ? void 0 : item.name) || ((_item_constructor = item.constructor) === null || _item_constructor === void 0 ? void 0 : _item_constructor.name);
121
+ return name === "HtmlWebpackPlugin";
122
+ });
123
+ if (isHtmlWebpackPlugin) {
124
+ chain.plugin(id).tap((options) => {
125
+ if (!options.length || options[0].minify) {
126
+ return options;
127
+ }
128
+ const userMinifyOption = options[0].minify;
129
+ options[0].minify = userMinifyOption ? (0, import_ts_deepmerge.merge)(minifyOptions, userMinifyOption) : minifyOptions;
130
+ return options;
131
+ });
132
+ }
133
+ }
134
+ });
135
+ }
136
+ });
137
+ // Annotate the CommonJS export names for ESM import in node:
138
+ 0 && (module.exports = {
139
+ pluginHtmlMinifierTerser
140
+ });
@@ -1,4 +1,3 @@
1
- import type { RsbuildPlugin } from '@rsbuild/core';
1
+ import type { RsbuildPlugin, RsbuildTarget } from '@rsbuild/core';
2
2
  import type { MainFields } from '../../types';
3
- import type { RsbuildTarget } from '@rsbuild/shared';
4
3
  export declare const pluginMainFields: (resolveMainFields: MainFields | Partial<Record<RsbuildTarget, MainFields>>) => RsbuildPlugin;
@@ -1,2 +1,2 @@
1
1
  import type { RsbuildPlugin } from '@rsbuild/core';
2
- export declare const pluginPostcssLegacy: (webBrowserslist: string[]) => RsbuildPlugin;
2
+ export declare const pluginPostcssLegacy: () => RsbuildPlugin;
@@ -21,16 +21,19 @@ __export(postcssLegacy_exports, {
21
21
  pluginPostcssLegacy: () => pluginPostcssLegacy
22
22
  });
23
23
  module.exports = __toCommonJS(postcssLegacy_exports);
24
- var import_shared = require("@rsbuild/shared");
24
+ var import_utils = require("@modern-js/utils");
25
25
  var import_getCssSupport = require("../getCssSupport");
26
- const pluginPostcssLegacy = (webBrowserslist) => ({
26
+ const pluginPostcssLegacy = () => ({
27
27
  name: "uni-builder:postcss-plugins",
28
28
  setup(api) {
29
- api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {
29
+ api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig }) => {
30
30
  var _config_output;
31
- const cssSupport = (0, import_getCssSupport.getCssSupport)(webBrowserslist);
31
+ if (config.output.target !== "web") {
32
+ return;
33
+ }
34
+ const cssSupport = (0, import_getCssSupport.getCssSupport)(config.output.overrideBrowserslist);
32
35
  const enableExtractCSS = !((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.injectStyles);
33
- const enableCssMinify = !enableExtractCSS && import_shared.isProd;
36
+ const enableCssMinify = !enableExtractCSS && import_utils.isProd;
34
37
  const plugins = [
35
38
  require("postcss-flexbugs-fixes"),
36
39
  !cssSupport.customProperties && require("postcss-custom-properties"),
@@ -51,7 +54,7 @@ const pluginPostcssLegacy = (webBrowserslist) => ({
51
54
  ]
52
55
  }) : false
53
56
  ].filter(Boolean);
54
- return mergeRsbuildConfig(
57
+ return mergeEnvironmentConfig(
55
58
  {
56
59
  tools: {
57
60
  postcss: (opts) => {
@@ -25,11 +25,11 @@ var import_utils = require("../utils");
25
25
  const pluginRuntimeChunk = (disableInlineRuntimeChunk) => ({
26
26
  name: "uni-builder:runtime-chunk",
27
27
  setup(api) {
28
- api.modifyBundlerChain(async (chain, { target }) => {
28
+ api.modifyBundlerChain(async (chain, { target, environment }) => {
29
29
  if (target !== "web") {
30
30
  return;
31
31
  }
32
- const config = api.getNormalizedConfig();
32
+ const { config } = environment;
33
33
  const { chunkSplit } = config.performance;
34
34
  if (chunkSplit.strategy !== "all-in-one") {
35
35
  chain.optimization.runtimeChunk({
@@ -21,13 +21,31 @@ __export(splitChunk_exports, {
21
21
  pluginSplitChunks: () => pluginSplitChunks
22
22
  });
23
23
  module.exports = __toCommonJS(splitChunk_exports);
24
- var import_shared = require("@rsbuild/shared");
25
24
  var import_utils = require("@modern-js/utils");
25
+ const DEP_MATCH_TEMPLATE = /[\\/]node_modules[\\/](<SOURCES>)[\\/]/.source;
26
+ const createDependenciesRegExp = (...dependencies) => {
27
+ const sources = dependencies.map((d) => typeof d === "string" ? d : d.source);
28
+ const expr = DEP_MATCH_TEMPLATE.replace("<SOURCES>", sources.join("|"));
29
+ return new RegExp(expr);
30
+ };
31
+ function createCacheGroups(group) {
32
+ const experienceCacheGroup = {};
33
+ for (const [name, pkgs] of Object.entries(group)) {
34
+ const key = `lib-${name}`;
35
+ experienceCacheGroup[key] = {
36
+ test: createDependenciesRegExp(...pkgs),
37
+ priority: 0,
38
+ name: key,
39
+ reuseExistingChunk: true
40
+ };
41
+ }
42
+ return experienceCacheGroup;
43
+ }
26
44
  const pluginSplitChunks = () => ({
27
45
  name: "uni-builder:split-chunks",
28
46
  setup(api) {
29
- api.modifyBundlerChain((chain) => {
30
- const config = api.getNormalizedConfig();
47
+ api.modifyBundlerChain((chain, { environment }) => {
48
+ const { config } = environment;
31
49
  const { chunkSplit } = config.performance || {};
32
50
  if ((chunkSplit === null || chunkSplit === void 0 ? void 0 : chunkSplit.strategy) !== "split-by-experience") {
33
51
  return;
@@ -60,7 +78,7 @@ const pluginSplitChunks = () => ({
60
78
  ...currentConfig,
61
79
  // rspack chunks type mismatch with webpack
62
80
  cacheGroups: {
63
- ...(0, import_shared.createCacheGroups)(groups),
81
+ ...createCacheGroups(groups),
64
82
  ...currentConfig.cacheGroups
65
83
  }
66
84
  });
@@ -1,5 +1,25 @@
1
- import type { RsbuildTarget, NormalizedConfig } from '@rsbuild/core';
1
+ import type { RsbuildTarget, RspackChain, RsbuildContext, NormalizedEnvironmentConfig } from '@rsbuild/core';
2
2
  export declare const RUNTIME_CHUNK_NAME = "builder-runtime";
3
+ export declare const SERVICE_WORKER_ENVIRONMENT_NAME = "serviceWorker";
4
+ export declare const JS_REGEX: RegExp;
3
5
  export declare const TS_REGEX: RegExp;
4
- export declare function isServerTarget(target: RsbuildTarget[]): boolean;
5
- export declare const getHash: (config: NormalizedConfig) => string;
6
+ export declare const SCRIPT_REGEX: RegExp;
7
+ export declare const NODE_MODULES_REGEX: RegExp;
8
+ export declare function isServerEnvironment(target: RsbuildTarget, environment: string): boolean;
9
+ export declare const castArray: <T>(arr?: T | T[] | undefined) => T[];
10
+ export declare const getUseBuiltIns: (config: NormalizedEnvironmentConfig) => false | 'usage' | 'entry';
11
+ export declare function applyScriptCondition({ rule, chain, config, context, includes, excludes, }: {
12
+ rule: RspackChain.Rule;
13
+ chain: RspackChain;
14
+ config: NormalizedEnvironmentConfig;
15
+ context: RsbuildContext;
16
+ includes: (string | RegExp)[];
17
+ excludes: (string | RegExp)[];
18
+ }): void;
19
+ export declare const isHtmlDisabled: (config: NormalizedEnvironmentConfig, target: RsbuildTarget) => boolean;
20
+ export declare const getHash: (config: NormalizedEnvironmentConfig) => string;
21
+ export declare function getBrowserslistWithDefault(path: string, config: {
22
+ output?: {
23
+ overrideBrowserslist?: string[];
24
+ };
25
+ }, target: RsbuildTarget): Promise<string[]>;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,25 +17,111 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var utils_exports = {};
20
30
  __export(utils_exports, {
31
+ JS_REGEX: () => JS_REGEX,
32
+ NODE_MODULES_REGEX: () => NODE_MODULES_REGEX,
21
33
  RUNTIME_CHUNK_NAME: () => RUNTIME_CHUNK_NAME,
34
+ SCRIPT_REGEX: () => SCRIPT_REGEX,
35
+ SERVICE_WORKER_ENVIRONMENT_NAME: () => SERVICE_WORKER_ENVIRONMENT_NAME,
22
36
  TS_REGEX: () => TS_REGEX,
37
+ applyScriptCondition: () => applyScriptCondition,
38
+ castArray: () => castArray,
39
+ getBrowserslistWithDefault: () => getBrowserslistWithDefault,
23
40
  getHash: () => getHash,
24
- isServerTarget: () => isServerTarget
41
+ getUseBuiltIns: () => getUseBuiltIns,
42
+ isHtmlDisabled: () => isHtmlDisabled,
43
+ isServerEnvironment: () => isServerEnvironment
25
44
  });
26
45
  module.exports = __toCommonJS(utils_exports);
46
+ var import_browserslist = __toESM(require("browserslist"));
27
47
  const RUNTIME_CHUNK_NAME = "builder-runtime";
48
+ const SERVICE_WORKER_ENVIRONMENT_NAME = "serviceWorker";
49
+ const JS_REGEX = /\.(?:js|mjs|cjs|jsx)$/;
28
50
  const TS_REGEX = /\.(?:ts|mts|cts|tsx)$/;
29
- function isServerTarget(target) {
30
- return (Array.isArray(target) ? target : [
31
- target
32
- ]).some((item) => [
33
- "node",
34
- "service-worker"
35
- ].includes(item));
51
+ const SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
52
+ const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
53
+ function isServerEnvironment(target, environment) {
54
+ return target === "node" || environment === SERVICE_WORKER_ENVIRONMENT_NAME;
36
55
  }
56
+ const castArray = (arr) => {
57
+ if (arr === void 0) {
58
+ return [];
59
+ }
60
+ return Array.isArray(arr) ? arr : [
61
+ arr
62
+ ];
63
+ };
64
+ const browsersListCache = /* @__PURE__ */ new Map();
65
+ async function getBrowserslist(path) {
66
+ const env = process.env.NODE_ENV;
67
+ const cacheKey = `${path}${env}`;
68
+ if (browsersListCache.has(cacheKey)) {
69
+ return browsersListCache.get(cacheKey);
70
+ }
71
+ const result = import_browserslist.default.loadConfig({
72
+ path,
73
+ env
74
+ });
75
+ if (result) {
76
+ browsersListCache.set(cacheKey, result);
77
+ return result;
78
+ }
79
+ return null;
80
+ }
81
+ const getUseBuiltIns = (config) => {
82
+ const { polyfill } = config.output;
83
+ if (polyfill === "off") {
84
+ return false;
85
+ }
86
+ return polyfill;
87
+ };
88
+ function applyScriptCondition({ rule, chain, config, context, includes, excludes }) {
89
+ rule.include.add({
90
+ and: [
91
+ context.rootPath,
92
+ {
93
+ not: NODE_MODULES_REGEX
94
+ }
95
+ ]
96
+ });
97
+ rule.include.add(/\.(?:ts|tsx|jsx|mts|cts)$/);
98
+ const target = castArray(chain.get("target"));
99
+ const legacyTarget = [
100
+ "es5",
101
+ "es6",
102
+ "es2015",
103
+ "es2016"
104
+ ];
105
+ if (legacyTarget.some((item) => target.includes(item))) {
106
+ rule.include.add(/[\\/]@rsbuild[\\/]core[\\/]dist[\\/]/);
107
+ }
108
+ for (const condition of [
109
+ ...includes,
110
+ ...config.source.include || []
111
+ ]) {
112
+ rule.include.add(condition);
113
+ }
114
+ for (const condition of [
115
+ ...excludes,
116
+ ...config.source.exclude || []
117
+ ]) {
118
+ rule.exclude.add(condition);
119
+ }
120
+ }
121
+ const isHtmlDisabled = (config, target) => {
122
+ const { htmlPlugin } = config.tools;
123
+ return htmlPlugin === false || Array.isArray(htmlPlugin) && htmlPlugin.includes(false) || target !== "web";
124
+ };
37
125
  const getHash = (config) => {
38
126
  const { filenameHash } = config.output;
39
127
  if (typeof filenameHash === "string") {
@@ -41,10 +129,44 @@ const getHash = (config) => {
41
129
  }
42
130
  return filenameHash ? ".[contenthash:8]" : "";
43
131
  };
132
+ const DEFAULT_WEB_BROWSERSLIST = [
133
+ "> 0.01%",
134
+ "not dead",
135
+ "not op_mini all"
136
+ ];
137
+ const DEFAULT_BROWSERSLIST = {
138
+ web: DEFAULT_WEB_BROWSERSLIST,
139
+ node: [
140
+ "node >= 14"
141
+ ],
142
+ "web-worker": DEFAULT_WEB_BROWSERSLIST
143
+ };
144
+ async function getBrowserslistWithDefault(path, config, target) {
145
+ const { overrideBrowserslist: overrides } = (config === null || config === void 0 ? void 0 : config.output) || {};
146
+ if (target === "web" || target === "web-worker") {
147
+ if (overrides) {
148
+ return overrides;
149
+ }
150
+ const browserslistrc = await getBrowserslist(path);
151
+ if (browserslistrc) {
152
+ return browserslistrc;
153
+ }
154
+ }
155
+ return DEFAULT_BROWSERSLIST[target];
156
+ }
44
157
  // Annotate the CommonJS export names for ESM import in node:
45
158
  0 && (module.exports = {
159
+ JS_REGEX,
160
+ NODE_MODULES_REGEX,
46
161
  RUNTIME_CHUNK_NAME,
162
+ SCRIPT_REGEX,
163
+ SERVICE_WORKER_ENVIRONMENT_NAME,
47
164
  TS_REGEX,
165
+ applyScriptCondition,
166
+ castArray,
167
+ getBrowserslistWithDefault,
48
168
  getHash,
49
- isServerTarget
169
+ getUseBuiltIns,
170
+ isHtmlDisabled,
171
+ isServerEnvironment
50
172
  });