@modern-js/uni-builder 2.46.0 → 2.47.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.
@@ -35,17 +35,19 @@ var import_isEqual = __toESM(require("lodash/isEqual"));
35
35
  var import_plugin_babel = require("@rsbuild/plugin-babel");
36
36
  const pluginBabelPost = () => ({
37
37
  name: "uni-builder:babel-post",
38
- pre: [
39
- "rsbuild:babel"
40
- ],
41
38
  setup(api) {
42
- api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
43
- if (chain.module.rules.get(CHAIN_ID.RULE.JS)) {
44
- const babelLoaderOptions = chain.module.rule(CHAIN_ID.RULE.JS).use(CHAIN_ID.USE.BABEL).get("options");
45
- if (babelLoaderOptions && (0, import_isEqual.default)((0, import_plugin_babel.getDefaultBabelOptions)(), babelLoaderOptions)) {
46
- chain.module.rule(CHAIN_ID.RULE.JS).uses.delete(CHAIN_ID.USE.BABEL);
39
+ api.modifyBundlerChain({
40
+ handler: async (chain, { CHAIN_ID }) => {
41
+ if (chain.module.rules.get(CHAIN_ID.RULE.JS)) {
42
+ const babelLoaderOptions = chain.module.rule(CHAIN_ID.RULE.JS).use(CHAIN_ID.USE.BABEL).get("options");
43
+ const config = api.getNormalizedConfig();
44
+ if (babelLoaderOptions && (0, import_isEqual.default)((0, import_plugin_babel.getDefaultBabelOptions)(config.source.decorators), babelLoaderOptions)) {
45
+ chain.module.rule(CHAIN_ID.RULE.JS).uses.delete(CHAIN_ID.USE.BABEL);
46
+ }
47
47
  }
48
- }
48
+ },
49
+ // other plugins can modify babel config in modifyBundlerChain 'default order'
50
+ order: "post"
49
51
  });
50
52
  }
51
53
  });
@@ -53,18 +53,12 @@ const getServerOptions = (builderConfig) => {
53
53
  };
54
54
  };
55
55
  const getDevServerOptions = async ({ builderConfig, serverOptions, port }) => {
56
- var _builderConfig_dev, _builderConfig_dev1, _builderConfig_dev2, _builderConfig_tools;
57
- var _builderConfig_dev_hmr, _builderConfig_dev_hmr1;
56
+ var _builderConfig_dev, _builderConfig_tools;
58
57
  const defaultDevConfig = (0, import_shared.deepmerge)(
59
58
  {
60
- hot: (_builderConfig_dev_hmr = (_builderConfig_dev = builderConfig.dev) === null || _builderConfig_dev === void 0 ? void 0 : _builderConfig_dev.hmr) !== null && _builderConfig_dev_hmr !== void 0 ? _builderConfig_dev_hmr : true,
61
59
  watch: true,
62
- client: {
63
- port: port.toString()
64
- },
65
60
  port,
66
- liveReload: (_builderConfig_dev_hmr1 = (_builderConfig_dev1 = builderConfig.dev) === null || _builderConfig_dev1 === void 0 ? void 0 : _builderConfig_dev1.hmr) !== null && _builderConfig_dev_hmr1 !== void 0 ? _builderConfig_dev_hmr1 : true,
67
- https: (_builderConfig_dev2 = builderConfig.dev) === null || _builderConfig_dev2 === void 0 ? void 0 : _builderConfig_dev2.https
61
+ https: (_builderConfig_dev = builderConfig.dev) === null || _builderConfig_dev === void 0 ? void 0 : _builderConfig_dev.https
68
62
  },
69
63
  // merge devServerOptions from serverOptions
70
64
  serverOptions.dev || {}
@@ -127,8 +121,8 @@ async function startDevServer(rsbuild, options = {}, builderConfig) {
127
121
  port,
128
122
  routes: [
129
123
  {
130
- route: "/",
131
- name: "index"
124
+ pathname: "/",
125
+ entryName: "index"
132
126
  }
133
127
  ]
134
128
  });
@@ -45,6 +45,8 @@ var import_plugin_css_minimizer = require("@rsbuild/plugin-css-minimizer");
45
45
  var import_postcssLegacy = require("./plugins/postcssLegacy");
46
46
  var import_devtools = require("./plugins/devtools");
47
47
  var import_emitRouteFile = require("./plugins/emitRouteFile");
48
+ var import_antd = require("./plugins/antd");
49
+ var import_arco = require("./plugins/arco");
48
50
  const GLOBAL_CSS_REGEX = /\.global\.\w+$/;
49
51
  const isLooseCssModules = (path) => {
50
52
  if (import_shared.NODE_MODULES_REGEX.test(path)) {
@@ -92,17 +94,48 @@ async function getBrowserslistWithDefault(path, config, target) {
92
94
  }
93
95
  return DEFAULT_BROWSERSLIST[target];
94
96
  }
97
+ const isUseCssSourceMap = (disableSourceMap = {}) => {
98
+ if (typeof disableSourceMap === "boolean") {
99
+ return !disableSourceMap;
100
+ }
101
+ if (disableSourceMap.css === void 0) {
102
+ return process.env.NODE_ENV !== "production";
103
+ }
104
+ return !disableSourceMap.css;
105
+ };
95
106
  async function parseCommonConfig(uniBuilderConfig, options) {
96
- var _uniBuilderConfig_output, _uniBuilderConfig_output1, _uniBuilderConfig_output2, _uniBuilderConfig_html, _uniBuilderConfig_html1, _uniBuilderConfig_html2, _uniBuilderConfig_html3, _uniBuilderConfig_html4, _uniBuilderConfig_html5, _devServer_devMiddleware, _uniBuilderConfig_source, _uniBuilderConfig_output3, _uniBuilderConfig_security, _uniBuilderConfig_output4, _uniBuilderConfig_source1, _uniBuilderConfig_source2, _uniBuilderConfig_output5, _uniBuilderConfig_output6, _uniBuilderConfig_output7, _uniBuilderConfig_tools, _uniBuilderConfig_output8, _uniBuilderConfig_output9, _uniBuilderConfig_tools1;
107
+ var _newDevServerConfig_devMiddleware, _uniBuilderConfig_output, _uniBuilderConfig_tools;
97
108
  var _output, _output_distPath, _output_distPath1, _output1, _extraConfig, _html, _extraConfig1;
98
109
  const { cwd, frameworkConfigPath, entry, target } = options;
99
- const rsbuildConfig = (0, import_shared.deepmerge)({}, uniBuilderConfig);
100
- const { dev = {}, html = {}, output = {}, tools = {} } = rsbuildConfig;
101
- if (output.cssModuleLocalIdentName) {
110
+ const { plugins: [...plugins] = [], performance: { ...performanceConfig } = {}, output: { disableFilenameHash, enableLatestDecorators, cssModuleLocalIdentName, enableInlineScripts, disableCssExtract, enableInlineStyles, disableCssModuleExtension, disableTsChecker, disableSvgr, svgDefaultExport, assetsRetry, enableAssetFallback, disableSourceMap, convertToRem, ...outputConfig } = {}, html: { disableHtmlFolder, metaByEntries, titleByEntries, faviconByEntries, injectByEntries, templateByEntries, templateParametersByEntries, ...htmlConfig } = {}, source: { alias, globalVars, resolveMainFields, resolveExtensionPrefix, ...sourceConfig } = {}, dev: { port, host, https, ...devConfig } = {}, security: { checkSyntax, sri, ...securityConfig } = {}, tools: { devServer, tsChecker, minifyCss, ...toolsConfig } = {} } = uniBuilderConfig;
111
+ const rsbuildConfig = {
112
+ plugins,
113
+ output: outputConfig,
114
+ source: {
115
+ alias,
116
+ ...sourceConfig
117
+ },
118
+ performance: performanceConfig,
119
+ html: htmlConfig,
120
+ tools: toolsConfig,
121
+ dev: devConfig,
122
+ security: securityConfig
123
+ };
124
+ const { dev = {}, html = {}, output = {}, source = {} } = rsbuildConfig;
125
+ if (enableLatestDecorators) {
126
+ source.decorators = {
127
+ version: "2022-03"
128
+ };
129
+ }
130
+ if (cssModuleLocalIdentName) {
102
131
  var _output2;
103
132
  (_output2 = output).cssModules || (_output2.cssModules = {});
104
- output.cssModules.localIdentName = output.cssModuleLocalIdentName;
105
- delete output.cssModuleLocalIdentName;
133
+ output.cssModules.localIdentName = cssModuleLocalIdentName;
134
+ }
135
+ if (isUseCssSourceMap(disableSourceMap)) {
136
+ var _output3;
137
+ (_output3 = output).sourceMap || (_output3.sourceMap = {});
138
+ output.sourceMap.css = true;
106
139
  }
107
140
  var _distPath;
108
141
  (_distPath = (_output = output).distPath) !== null && _distPath !== void 0 ? _distPath : _output.distPath = {};
@@ -112,22 +145,17 @@ async function parseCommonConfig(uniBuilderConfig, options) {
112
145
  (_server = (_output_distPath1 = output.distPath).server) !== null && _server !== void 0 ? _server : _output_distPath1.server = "bundles";
113
146
  var _polyfill;
114
147
  (_polyfill = (_output1 = output).polyfill) !== null && _polyfill !== void 0 ? _polyfill : _output1.polyfill = "entry";
115
- if (output.disableCssModuleExtension) {
116
- var _output3, _output_cssModules;
117
- (_output3 = output).cssModules || (_output3.cssModules = {});
148
+ if (disableCssModuleExtension) {
149
+ var _output4, _output_cssModules;
150
+ (_output4 = output).cssModules || (_output4.cssModules = {});
118
151
  var _auto;
119
152
  (_auto = (_output_cssModules = output.cssModules).auto) !== null && _auto !== void 0 ? _auto : _output_cssModules.auto = isLooseCssModules;
120
- delete output.cssModuleLocalIdentName;
121
153
  }
122
- if ((_uniBuilderConfig_output = uniBuilderConfig.output) === null || _uniBuilderConfig_output === void 0 ? void 0 : _uniBuilderConfig_output.enableInlineScripts) {
123
- var _uniBuilderConfig_output10;
124
- output.inlineScripts = (_uniBuilderConfig_output10 = uniBuilderConfig.output) === null || _uniBuilderConfig_output10 === void 0 ? void 0 : _uniBuilderConfig_output10.enableInlineScripts;
125
- delete output.enableInlineScripts;
154
+ if (enableInlineScripts) {
155
+ output.inlineScripts = enableInlineScripts;
126
156
  }
127
- if ((_uniBuilderConfig_output1 = uniBuilderConfig.output) === null || _uniBuilderConfig_output1 === void 0 ? void 0 : _uniBuilderConfig_output1.disableCssExtract) {
128
- var _uniBuilderConfig_output11;
129
- output.injectStyles = (_uniBuilderConfig_output11 = uniBuilderConfig.output) === null || _uniBuilderConfig_output11 === void 0 ? void 0 : _uniBuilderConfig_output11.disableCssExtract;
130
- delete output.disableCssExtract;
157
+ if (disableCssExtract) {
158
+ output.injectStyles = disableCssExtract;
131
159
  }
132
160
  const targets = Array.isArray(target) ? target : [
133
161
  target || "web"
@@ -138,40 +166,34 @@ async function parseCommonConfig(uniBuilderConfig, options) {
138
166
  overrideBrowserslist[target2] = await getBrowserslistWithDefault(cwd, uniBuilderConfig, target2);
139
167
  }
140
168
  output.overrideBrowserslist = overrideBrowserslist;
141
- if ((_uniBuilderConfig_output2 = uniBuilderConfig.output) === null || _uniBuilderConfig_output2 === void 0 ? void 0 : _uniBuilderConfig_output2.enableInlineStyles) {
142
- var _uniBuilderConfig_output12;
143
- output.inlineStyles = (_uniBuilderConfig_output12 = uniBuilderConfig.output) === null || _uniBuilderConfig_output12 === void 0 ? void 0 : _uniBuilderConfig_output12.enableInlineStyles;
144
- delete output.enableInlineStyles;
169
+ if (enableInlineStyles) {
170
+ output.inlineStyles = enableInlineStyles;
171
+ }
172
+ if (disableFilenameHash !== void 0) {
173
+ output.filenameHash = !disableFilenameHash;
145
174
  }
146
175
  const extraConfig = {};
147
176
  (_extraConfig = extraConfig).html || (_extraConfig.html = {});
148
- extraConfig.html.outputStructure = html.disableHtmlFolder ? "flat" : "nested";
149
- delete html.disableHtmlFolder;
150
- if ((_uniBuilderConfig_html = uniBuilderConfig.html) === null || _uniBuilderConfig_html === void 0 ? void 0 : _uniBuilderConfig_html.metaByEntries) {
151
- extraConfig.html.meta = ({ entryName }) => uniBuilderConfig.html.metaByEntries[entryName];
152
- delete html.metaByEntries;
177
+ extraConfig.html.outputStructure = disableHtmlFolder ? "flat" : "nested";
178
+ if (metaByEntries) {
179
+ extraConfig.html.meta = ({ entryName }) => metaByEntries[entryName];
153
180
  }
154
181
  var _title;
155
182
  (_title = (_html = html).title) !== null && _title !== void 0 ? _title : _html.title = "";
156
- if ((_uniBuilderConfig_html1 = uniBuilderConfig.html) === null || _uniBuilderConfig_html1 === void 0 ? void 0 : _uniBuilderConfig_html1.titleByEntries) {
157
- extraConfig.html.title = ({ entryName }) => uniBuilderConfig.html.titleByEntries[entryName];
158
- delete html.titleByEntries;
183
+ if (titleByEntries) {
184
+ extraConfig.html.title = ({ entryName }) => titleByEntries[entryName];
159
185
  }
160
- if ((_uniBuilderConfig_html2 = uniBuilderConfig.html) === null || _uniBuilderConfig_html2 === void 0 ? void 0 : _uniBuilderConfig_html2.faviconByEntries) {
161
- extraConfig.html.favicon = ({ entryName }) => uniBuilderConfig.html.faviconByEntries[entryName];
162
- delete html.faviconByEntries;
186
+ if (faviconByEntries) {
187
+ extraConfig.html.favicon = ({ entryName }) => faviconByEntries[entryName];
163
188
  }
164
- if ((_uniBuilderConfig_html3 = uniBuilderConfig.html) === null || _uniBuilderConfig_html3 === void 0 ? void 0 : _uniBuilderConfig_html3.injectByEntries) {
165
- extraConfig.html.inject = ({ entryName }) => uniBuilderConfig.html.injectByEntries[entryName];
166
- delete html.injectByEntries;
189
+ if (injectByEntries) {
190
+ extraConfig.html.inject = ({ entryName }) => injectByEntries[entryName];
167
191
  }
168
- if ((_uniBuilderConfig_html4 = uniBuilderConfig.html) === null || _uniBuilderConfig_html4 === void 0 ? void 0 : _uniBuilderConfig_html4.templateByEntries) {
169
- extraConfig.html.template = ({ entryName }) => uniBuilderConfig.html.templateByEntries[entryName];
170
- delete html.templateByEntries;
192
+ if (templateByEntries) {
193
+ extraConfig.html.template = ({ entryName }) => templateByEntries[entryName];
171
194
  }
172
- if ((_uniBuilderConfig_html5 = uniBuilderConfig.html) === null || _uniBuilderConfig_html5 === void 0 ? void 0 : _uniBuilderConfig_html5.templateParametersByEntries) {
173
- extraConfig.html.templateParameters = (_, { entryName }) => uniBuilderConfig.html.templateParametersByEntries[entryName];
174
- delete html.templateParametersByEntries;
195
+ if (templateParametersByEntries) {
196
+ extraConfig.html.templateParameters = (_, { entryName }) => templateParametersByEntries[entryName];
175
197
  }
176
198
  var _tools;
177
199
  (_tools = (_extraConfig1 = extraConfig).tools) !== null && _tools !== void 0 ? _tools : _extraConfig1.tools = {};
@@ -191,24 +213,33 @@ async function parseCommonConfig(uniBuilderConfig, options) {
191
213
  if (dev.progressBar === void 0) {
192
214
  dev.progressBar = true;
193
215
  }
194
- const devServer = (0, import_shared.mergeChainedOptions)({
216
+ var _dev_hmr;
217
+ const newDevServerConfig = (0, import_shared.mergeChainedOptions)({
195
218
  defaults: {
196
219
  devMiddleware: {
197
220
  writeToDisk: (file) => !file.includes(".hot-update.")
221
+ },
222
+ hot: (_dev_hmr = dev === null || dev === void 0 ? void 0 : dev.hmr) !== null && _dev_hmr !== void 0 ? _dev_hmr : true,
223
+ liveReload: true,
224
+ client: {
225
+ path: "/webpack-hmr"
198
226
  }
199
227
  },
200
- options: tools.devServer,
228
+ options: devServer,
201
229
  mergeFn: import_shared.deepmerge
202
230
  });
203
- dev.writeToDisk = (_devServer_devMiddleware = devServer.devMiddleware) === null || _devServer_devMiddleware === void 0 ? void 0 : _devServer_devMiddleware.writeToDisk;
204
- const server = (0, import_shared.isProd)() ? {} : {
205
- port: dev.port,
206
- host: dev.host
231
+ dev.writeToDisk = (_newDevServerConfig_devMiddleware = newDevServerConfig.devMiddleware) === null || _newDevServerConfig_devMiddleware === void 0 ? void 0 : _newDevServerConfig_devMiddleware.writeToDisk;
232
+ dev.hmr = newDevServerConfig.hot;
233
+ dev.client = newDevServerConfig.client;
234
+ dev.liveReload = newDevServerConfig.liveReload;
235
+ const server = (0, import_shared.isProd)() ? {
236
+ publicDir: false
237
+ } : {
238
+ publicDir: false,
239
+ port,
240
+ host,
241
+ https: https ? https : void 0
207
242
  };
208
- delete tools.devServer;
209
- delete dev.https;
210
- delete dev.port;
211
- delete dev.host;
212
243
  rsbuildConfig.server = removeUndefinedKey(server);
213
244
  rsbuildConfig.dev = removeUndefinedKey(dev);
214
245
  rsbuildConfig.html = html;
@@ -221,58 +252,50 @@ async function parseCommonConfig(uniBuilderConfig, options) {
221
252
  }
222
253
  const rsbuildPlugins = [
223
254
  (0, import_splitChunk.pluginSplitChunks)(),
224
- (0, import_globalVars.pluginGlobalVars)((_uniBuilderConfig_source = uniBuilderConfig.source) === null || _uniBuilderConfig_source === void 0 ? void 0 : _uniBuilderConfig_source.globalVars),
255
+ (0, import_globalVars.pluginGlobalVars)(globalVars),
225
256
  (0, import_devtools.pluginDevtool)({
226
- disableSourceMap: (_uniBuilderConfig_output3 = uniBuilderConfig.output) === null || _uniBuilderConfig_output3 === void 0 ? void 0 : _uniBuilderConfig_output3.disableSourceMap
257
+ disableSourceMap
227
258
  }),
228
259
  (0, import_emitRouteFile.pluginEmitRouteFile)(),
229
260
  (0, import_plugin_toml.pluginToml)(),
230
- (0, import_plugin_yaml.pluginYaml)()
261
+ (0, import_plugin_yaml.pluginYaml)(),
262
+ (0, import_antd.pluginAntd)(),
263
+ (0, import_arco.pluginArco)()
231
264
  ];
232
- const checkSyntaxOptions = (_uniBuilderConfig_security = uniBuilderConfig.security) === null || _uniBuilderConfig_security === void 0 ? void 0 : _uniBuilderConfig_security.checkSyntax;
233
- if (checkSyntaxOptions) {
265
+ if (checkSyntax) {
234
266
  const { pluginCheckSyntax } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-check-syntax")));
235
- rsbuildPlugins.push(pluginCheckSyntax(typeof checkSyntaxOptions === "boolean" ? {} : checkSyntaxOptions));
267
+ rsbuildPlugins.push(pluginCheckSyntax(typeof checkSyntax === "boolean" ? {} : checkSyntax));
236
268
  }
237
- if (!((_uniBuilderConfig_output4 = uniBuilderConfig.output) === null || _uniBuilderConfig_output4 === void 0 ? void 0 : _uniBuilderConfig_output4.disableTsChecker)) {
238
- var _uniBuilderConfig_tools2;
269
+ if (!disableTsChecker) {
239
270
  const { pluginTypeCheck } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-type-check")));
240
271
  rsbuildPlugins.push(pluginTypeCheck({
241
- forkTsCheckerOptions: (_uniBuilderConfig_tools2 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools2 === void 0 ? void 0 : _uniBuilderConfig_tools2.tsChecker
272
+ forkTsCheckerOptions: tsChecker
242
273
  }));
243
- delete output.disableTsChecker;
244
- delete tools.tsChecker;
245
274
  }
246
- if ((_uniBuilderConfig_source1 = uniBuilderConfig.source) === null || _uniBuilderConfig_source1 === void 0 ? void 0 : _uniBuilderConfig_source1.resolveMainFields) {
247
- var _uniBuilderConfig_source3;
275
+ if (resolveMainFields) {
248
276
  const { pluginMainFields } = await Promise.resolve().then(() => __toESM(require("./plugins/mainFields")));
249
- rsbuildPlugins.push(pluginMainFields((_uniBuilderConfig_source3 = uniBuilderConfig.source) === null || _uniBuilderConfig_source3 === void 0 ? void 0 : _uniBuilderConfig_source3.resolveMainFields));
277
+ rsbuildPlugins.push(pluginMainFields(resolveMainFields));
250
278
  }
251
- if ((_uniBuilderConfig_source2 = uniBuilderConfig.source) === null || _uniBuilderConfig_source2 === void 0 ? void 0 : _uniBuilderConfig_source2.resolveExtensionPrefix) {
252
- var _uniBuilderConfig_source4;
279
+ if (resolveExtensionPrefix) {
253
280
  const { pluginExtensionPrefix } = await Promise.resolve().then(() => __toESM(require("./plugins/extensionPrefix")));
254
- rsbuildPlugins.push(pluginExtensionPrefix((_uniBuilderConfig_source4 = uniBuilderConfig.source) === null || _uniBuilderConfig_source4 === void 0 ? void 0 : _uniBuilderConfig_source4.resolveExtensionPrefix));
281
+ rsbuildPlugins.push(pluginExtensionPrefix(resolveExtensionPrefix));
255
282
  }
256
- const remOptions = (_uniBuilderConfig_output5 = uniBuilderConfig.output) === null || _uniBuilderConfig_output5 === void 0 ? void 0 : _uniBuilderConfig_output5.convertToRem;
257
- if (remOptions) {
283
+ if (convertToRem) {
258
284
  const { pluginRem } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-rem")));
259
- rsbuildPlugins.push(pluginRem(typeof remOptions === "boolean" ? {} : remOptions));
285
+ rsbuildPlugins.push(pluginRem(typeof convertToRem === "boolean" ? {} : convertToRem));
260
286
  }
261
- rsbuildPlugins.push((0, import_runtimeChunk.pluginRuntimeChunk)((_uniBuilderConfig_output6 = uniBuilderConfig.output) === null || _uniBuilderConfig_output6 === void 0 ? void 0 : _uniBuilderConfig_output6.disableInlineRuntimeChunk));
287
+ rsbuildPlugins.push((0, import_runtimeChunk.pluginRuntimeChunk)((_uniBuilderConfig_output = uniBuilderConfig.output) === null || _uniBuilderConfig_output === void 0 ? void 0 : _uniBuilderConfig_output.disableInlineRuntimeChunk));
262
288
  const { sourceBuild } = uniBuilderConfig.experiments || {};
263
289
  if (sourceBuild) {
264
290
  const { pluginSourceBuild } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-source-build")));
265
291
  rsbuildPlugins.push(pluginSourceBuild(sourceBuild === true ? {} : sourceBuild));
266
292
  }
267
293
  rsbuildPlugins.push((0, import_plugin_react.pluginReact)());
268
- if (!((_uniBuilderConfig_output7 = uniBuilderConfig.output) === null || _uniBuilderConfig_output7 === void 0 ? void 0 : _uniBuilderConfig_output7.disableSvgr)) {
269
- var _uniBuilderConfig_output13;
294
+ if (!disableSvgr) {
270
295
  const { pluginSvgr } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-svgr")));
271
296
  rsbuildPlugins.push(pluginSvgr({
272
- svgDefaultExport: ((_uniBuilderConfig_output13 = uniBuilderConfig.output) === null || _uniBuilderConfig_output13 === void 0 ? void 0 : _uniBuilderConfig_output13.svgDefaultExport) || "url"
297
+ svgDefaultExport: svgDefaultExport || "url"
273
298
  }));
274
- delete output.disableSvgr;
275
- delete output.svgDefaultExport;
276
299
  }
277
300
  const pugOptions = (_uniBuilderConfig_tools = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools === void 0 ? void 0 : _uniBuilderConfig_tools.pug;
278
301
  if (pugOptions) {
@@ -281,12 +304,11 @@ async function parseCommonConfig(uniBuilderConfig, options) {
281
304
  pugOptions
282
305
  }));
283
306
  }
284
- if ((_uniBuilderConfig_output8 = uniBuilderConfig.output) === null || _uniBuilderConfig_output8 === void 0 ? void 0 : _uniBuilderConfig_output8.assetsRetry) {
285
- var _uniBuilderConfig_output14;
307
+ if (assetsRetry) {
286
308
  const { pluginAssetsRetry } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-assets-retry")));
287
- rsbuildPlugins.push(pluginAssetsRetry((_uniBuilderConfig_output14 = uniBuilderConfig.output) === null || _uniBuilderConfig_output14 === void 0 ? void 0 : _uniBuilderConfig_output14.assetsRetry));
309
+ rsbuildPlugins.push(pluginAssetsRetry(assetsRetry));
288
310
  }
289
- if ((_uniBuilderConfig_output9 = uniBuilderConfig.output) === null || _uniBuilderConfig_output9 === void 0 ? void 0 : _uniBuilderConfig_output9.enableAssetFallback) {
311
+ if (enableAssetFallback) {
290
312
  const { pluginFallback } = await Promise.resolve().then(() => __toESM(require("./plugins/fallback")));
291
313
  rsbuildPlugins.push(pluginFallback());
292
314
  }
@@ -294,7 +316,7 @@ async function parseCommonConfig(uniBuilderConfig, options) {
294
316
  rsbuildPlugins.push((0, import_frameworkConfig.pluginFrameworkConfig)(frameworkConfigPath));
295
317
  }
296
318
  rsbuildPlugins.push((0, import_plugin_css_minimizer.pluginCssMinimizer)({
297
- pluginOptions: (_uniBuilderConfig_tools1 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools1 === void 0 ? void 0 : _uniBuilderConfig_tools1.minifyCss
319
+ pluginOptions: minifyCss
298
320
  }));
299
321
  targets.includes("web") && rsbuildPlugins.push((0, import_postcssLegacy.pluginPostcssLegacy)(overrideBrowserslist.web));
300
322
  return {
@@ -0,0 +1,2 @@
1
+ import { type RsbuildPlugin } from '@rsbuild/shared';
2
+ export declare const pluginAntd: () => RsbuildPlugin;
@@ -0,0 +1,69 @@
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 antd_exports = {};
20
+ __export(antd_exports, {
21
+ pluginAntd: () => pluginAntd
22
+ });
23
+ module.exports = __toCommonJS(antd_exports);
24
+ var import_shared = require("@rsbuild/shared");
25
+ const getAntdMajorVersion = (appDirectory) => {
26
+ try {
27
+ const pkgJsonPath = require.resolve("antd/package.json", {
28
+ paths: [
29
+ appDirectory
30
+ ]
31
+ });
32
+ const { version } = require(pkgJsonPath);
33
+ return Number(version.split(".")[0]);
34
+ } catch (err) {
35
+ return null;
36
+ }
37
+ };
38
+ const pluginAntd = () => ({
39
+ name: "uni-builder:antd",
40
+ setup(api) {
41
+ api.modifyRsbuildConfig((rsbuildConfig) => {
42
+ var _rsbuildConfig_source_transformImport;
43
+ var _rsbuildConfig;
44
+ var _source;
45
+ (_source = (_rsbuildConfig = rsbuildConfig).source) !== null && _source !== void 0 ? _source : _rsbuildConfig.source = {};
46
+ 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
+ return;
48
+ }
49
+ const antdMajorVersion = getAntdMajorVersion(api.context.rootPath);
50
+ if (antdMajorVersion && antdMajorVersion < 5) {
51
+ var _rsbuildConfig1;
52
+ var _source1;
53
+ (_source1 = (_rsbuildConfig1 = rsbuildConfig).source) !== null && _source1 !== void 0 ? _source1 : _rsbuildConfig1.source = {};
54
+ rsbuildConfig.source.transformImport = [
55
+ ...rsbuildConfig.source.transformImport || [],
56
+ {
57
+ libraryName: "antd",
58
+ libraryDirectory: (0, import_shared.isServerTarget)(api.context.targets) ? "lib" : "es",
59
+ style: true
60
+ }
61
+ ];
62
+ }
63
+ });
64
+ }
65
+ });
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ pluginAntd
69
+ });
@@ -0,0 +1,2 @@
1
+ import { type RsbuildPlugin } from '@rsbuild/shared';
2
+ export declare const pluginArco: () => RsbuildPlugin;
@@ -0,0 +1,61 @@
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 arco_exports = {};
20
+ __export(arco_exports, {
21
+ pluginArco: () => pluginArco
22
+ });
23
+ module.exports = __toCommonJS(arco_exports);
24
+ var import_shared = require("@rsbuild/shared");
25
+ var import_utils = require("@modern-js/utils");
26
+ const pluginArco = () => ({
27
+ name: "uni-builder:arco",
28
+ setup(api) {
29
+ const ARCO_NAME = "@arco-design/web-react";
30
+ const ARCO_ICON = `${ARCO_NAME}/icon`;
31
+ api.modifyRsbuildConfig((rsbuildConfig) => {
32
+ var _rsbuildConfig;
33
+ const { transformImport = [] } = rsbuildConfig.source || {};
34
+ if (transformImport === false || !(0, import_utils.isPackageInstalled)(ARCO_NAME, api.context.rootPath)) {
35
+ return;
36
+ }
37
+ const isUseSSR = (0, import_shared.isServerTarget)(api.context.targets);
38
+ if (!(transformImport === null || transformImport === void 0 ? void 0 : transformImport.some((item) => item.libraryName === ARCO_NAME))) {
39
+ transformImport.push({
40
+ libraryName: ARCO_NAME,
41
+ libraryDirectory: isUseSSR ? "lib" : "es",
42
+ camelToDashComponentName: false,
43
+ style: true
44
+ });
45
+ }
46
+ if (!(transformImport === null || transformImport === void 0 ? void 0 : transformImport.some((item) => item.libraryName === ARCO_ICON))) {
47
+ transformImport.push({
48
+ libraryName: ARCO_ICON,
49
+ libraryDirectory: isUseSSR ? "react-icon-cjs" : "react-icon",
50
+ camelToDashComponentName: false
51
+ });
52
+ }
53
+ (_rsbuildConfig = rsbuildConfig).source || (_rsbuildConfig.source = {});
54
+ rsbuildConfig.source.transformImport = transformImport;
55
+ });
56
+ }
57
+ });
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ pluginArco
61
+ });
@@ -87,14 +87,17 @@ const pluginFallback = () => ({
87
87
  } else {
88
88
  api.modifyRspackConfig((config, { isProd }) => {
89
89
  var _config_module;
90
+ var _config, _config1;
90
91
  const rsbuildConfig = api.getNormalizedConfig();
91
92
  const distDir = (0, import_shared.getDistPath)(rsbuildConfig, "media");
92
93
  const filename = (0, import_shared.getFilename)(rsbuildConfig, "media", isProd);
93
- (0, import_shared.setConfig)(config, "output.assetModuleFilename", (0, import_path.join)(distDir, filename));
94
+ (_config = config).output || (_config.output = {});
95
+ config.output.assetModuleFilename = (0, import_path.join)(distDir, filename);
94
96
  if (!config.module) {
95
97
  return;
96
98
  }
97
- (0, import_shared.setConfig)(config, "module.rules", resourceRuleFallback((_config_module = config.module) === null || _config_module === void 0 ? void 0 : _config_module.rules));
99
+ (_config1 = config).module || (_config1.module = {});
100
+ config.module.rules = resourceRuleFallback((_config_module = config.module) === null || _config_module === void 0 ? void 0 : _config_module.rules);
98
101
  });
99
102
  }
100
103
  }
@@ -31,6 +31,7 @@ const pluginPostcssLegacy = (webBrowserslist) => ({
31
31
  const enableExtractCSS = (0, import_shared.isUseCssExtract)(config, "web");
32
32
  const enableCssMinify = !enableExtractCSS && import_shared.isProd;
33
33
  const plugins = [
34
+ require("postcss-flexbugs-fixes"),
34
35
  !cssSupport.customProperties && require("postcss-custom-properties"),
35
36
  !cssSupport.initial && require("postcss-initial"),
36
37
  !cssSupport.pageBreak && require("postcss-page-break"),
@@ -22,6 +22,7 @@ __export(splitChunk_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(splitChunk_exports);
24
24
  var import_shared = require("@rsbuild/shared");
25
+ var import_utils = require("@modern-js/utils");
25
26
  const pluginSplitChunks = () => ({
26
27
  name: "uni-builder:split-chunks",
27
28
  setup(api) {
@@ -32,22 +33,22 @@ const pluginSplitChunks = () => ({
32
33
  return;
33
34
  }
34
35
  const currentConfig = chain.optimization.splitChunks.values();
35
- if (!(0, import_shared.isPlainObject)(currentConfig)) {
36
+ if (!(0, import_utils.isPlainObject)(currentConfig)) {
36
37
  return;
37
38
  }
38
39
  const groups = {};
39
40
  const { rootPath } = api.context;
40
- if ((0, import_shared.isPackageInstalled)("antd", rootPath)) {
41
+ if ((0, import_utils.isPackageInstalled)("antd", rootPath)) {
41
42
  groups.antd = [
42
43
  "antd"
43
44
  ];
44
45
  }
45
- if ((0, import_shared.isPackageInstalled)("@arco-design/web-react", rootPath)) {
46
+ if ((0, import_utils.isPackageInstalled)("@arco-design/web-react", rootPath)) {
46
47
  groups.arco = [
47
48
  /@?arco-design/
48
49
  ];
49
50
  }
50
- if ((0, import_shared.isPackageInstalled)("@douyinfe/semi-ui", rootPath)) {
51
+ if ((0, import_utils.isPackageInstalled)("@douyinfe/semi-ui", rootPath)) {
51
52
  groups.semi = [
52
53
  /@(ies|douyinfe)[\\/]semi-.*/
53
54
  ];
package/dist/types.d.ts CHANGED
@@ -51,6 +51,7 @@ export type UniBuilderExtraConfig = {
51
51
  devMiddleware?: {
52
52
  writeToDisk?: DevConfig['writeToDisk'];
53
53
  };
54
+ liveReload?: boolean;
54
55
  headers?: ServerConfig['headers'];
55
56
  historyApiFallback?: ServerConfig['historyApiFallback'];
56
57
  hot?: boolean;
@@ -121,6 +122,14 @@ export type UniBuilderExtraConfig = {
121
122
  resolveExtensionPrefix?: string | Partial<Record<RsbuildTarget, string>>;
122
123
  };
123
124
  output?: {
125
+ /**
126
+ * @deprecated use `output.filenameHash` instead
127
+ */
128
+ disableFilenameHash?: boolean;
129
+ /**
130
+ * @deprecated use `source.decorators` instead
131
+ */
132
+ enableLatestDecorators?: boolean;
124
133
  /**
125
134
  * @deprecated use `output.cssModules.localIdentName` instead
126
135
  */
@@ -211,6 +220,15 @@ export type UniBuilderExtraConfig = {
211
220
  */
212
221
  templateParametersByEntries?: Record<string, Record<string, unknown>>;
213
222
  };
223
+ performance?: {
224
+ /**
225
+ * Specifies whether to modularize the import of [lodash](https://npmjs.com/package/lodash)
226
+ * and remove unused lodash modules to reduce the code size of lodash.
227
+ *
228
+ * Tips: this configuration is not yet supported in rspack
229
+ */
230
+ transformLodash?: boolean;
231
+ };
214
232
  security?: {
215
233
  /**
216
234
  * Adding an integrity attribute (`integrity`) to sub-resources introduced by HTML allows the browser to
@@ -39,10 +39,13 @@ var import_moduleScopes = require("./plugins/moduleScopes");
39
39
  var import_babel = require("./plugins/babel");
40
40
  var import_react = require("./plugins/react");
41
41
  async function parseConfig(uniBuilderConfig, options) {
42
- var _uniBuilderConfig_tools, _uniBuilderConfig_tools1, _uniBuilderConfig_output, _uniBuilderConfig_security, _uniBuilderConfig_experiments, _uniBuilderConfig_tools2;
42
+ var _uniBuilderConfig_tools, _uniBuilderConfig_performance, _uniBuilderConfig_tools1, _uniBuilderConfig_output, _uniBuilderConfig_security, _uniBuilderConfig_experiments, _uniBuilderConfig_tools2;
43
43
  const { rsbuildConfig, rsbuildPlugins } = await (0, import_parseCommonConfig.parseCommonConfig)(uniBuilderConfig, options);
44
+ var _uniBuilderConfig_performance_transformLodash;
44
45
  rsbuildPlugins.push((0, import_babel.pluginBabel)({
45
46
  babelLoaderOptions: (_uniBuilderConfig_tools = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools === void 0 ? void 0 : _uniBuilderConfig_tools.babel
47
+ }, {
48
+ transformLodash: (_uniBuilderConfig_performance_transformLodash = (_uniBuilderConfig_performance = uniBuilderConfig.performance) === null || _uniBuilderConfig_performance === void 0 ? void 0 : _uniBuilderConfig_performance.transformLodash) !== null && _uniBuilderConfig_performance_transformLodash !== void 0 ? _uniBuilderConfig_performance_transformLodash : true
46
49
  }));
47
50
  rsbuildPlugins.push((0, import_react.pluginReact)());
48
51
  if ((_uniBuilderConfig_tools1 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools1 === void 0 ? void 0 : _uniBuilderConfig_tools1.tsLoader) {
@@ -1,3 +1,16 @@
1
1
  import { type RsbuildPlugin } from '@rsbuild/shared';
2
2
  import { type PluginBabelOptions } from '@rsbuild/plugin-babel';
3
- export declare const pluginBabel: (options?: PluginBabelOptions) => RsbuildPlugin;
3
+ /**
4
+ * Plugin order:
5
+ * rspack mode: rsbuild:swc -> rsbuild:babel
6
+ * webpack mode: uni-builder:babel -> uni-builder:ts-loader -> rsbuild-webpack:swc
7
+ */
8
+ export declare const getPresetReact: (rootPath: string, isProd: boolean) => (string | {
9
+ development: boolean;
10
+ useBuiltIns: boolean;
11
+ useSpread: boolean;
12
+ runtime: string;
13
+ })[];
14
+ export declare const pluginBabel: (options: PluginBabelOptions, extraOptions: {
15
+ transformLodash: boolean;
16
+ }) => RsbuildPlugin;
@@ -28,124 +28,135 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var babel_exports = {};
30
30
  __export(babel_exports, {
31
+ getPresetReact: () => getPresetReact,
31
32
  pluginBabel: () => pluginBabel
32
33
  });
33
34
  module.exports = __toCommonJS(babel_exports);
34
35
  var import_cloneDeep = __toESM(require("lodash/cloneDeep"));
35
36
  var import_web = require("@rsbuild/babel-preset/web");
36
37
  var import_node = require("@rsbuild/babel-preset/node");
37
- var import_plugin_react = require("@rsbuild/plugin-react");
38
+ var import_utils = require("@modern-js/utils");
38
39
  var import_shared = require("@rsbuild/shared");
39
40
  var import_plugin_babel = require("@rsbuild/plugin-babel");
40
- const pluginBabel = (options) => ({
41
+ const getPresetReact = (rootPath, isProd) => {
42
+ const isNewJsx = (0, import_utils.isBeyondReact17)(rootPath);
43
+ const presetReactOptions = {
44
+ development: !isProd,
45
+ // Will use the native built-in instead of trying to polyfill
46
+ useBuiltIns: true,
47
+ useSpread: false,
48
+ runtime: isNewJsx ? "automatic" : "classic"
49
+ };
50
+ return [
51
+ require.resolve("@babel/preset-react"),
52
+ presetReactOptions
53
+ ];
54
+ };
55
+ const pluginBabel = (options, extraOptions) => ({
41
56
  name: "uni-builder:babel",
57
+ post: [
58
+ // will replace the babel rule
59
+ "rsbuild-webpack:swc",
60
+ // will replace the babel rule
61
+ "rsbuild-webpack:esbuild"
62
+ ],
42
63
  setup(api) {
43
- api.modifyBundlerChain(async (chain, { CHAIN_ID, target, isProd, isServer, isServiceWorker }) => {
44
- const config = api.getNormalizedConfig();
45
- const browserslist = await (0, import_shared.getBrowserslistWithDefault)(api.context.rootPath, config, target);
46
- const isNewJsx = await (0, import_plugin_react.isBeyondReact17)(api.context.rootPath);
47
- const getBabelOptions = (config2) => {
48
- var _baseBabelConfig_presets;
49
- const includes2 = [];
50
- const excludes2 = [];
51
- const babelUtils = {
52
- addIncludes(items) {
53
- if (Array.isArray(items)) {
54
- includes2.push(...items);
55
- } else {
56
- includes2.push(items);
57
- }
58
- },
59
- addExcludes(items) {
60
- if (Array.isArray(items)) {
61
- excludes2.push(...items);
62
- } else {
63
- excludes2.push(items);
64
+ api.modifyBundlerChain({
65
+ order: "pre",
66
+ handler: async (chain, { CHAIN_ID, target, isProd, isServer, isServiceWorker }) => {
67
+ const config = api.getNormalizedConfig();
68
+ const browserslist = await (0, import_shared.getBrowserslistWithDefault)(api.context.rootPath, config, target);
69
+ const getBabelOptions = (config2) => {
70
+ var _baseBabelConfig_presets;
71
+ const includes2 = [];
72
+ const excludes2 = [];
73
+ const babelUtils = {
74
+ addIncludes(items) {
75
+ if (Array.isArray(items)) {
76
+ includes2.push(...items);
77
+ } else {
78
+ includes2.push(items);
79
+ }
80
+ },
81
+ addExcludes(items) {
82
+ if (Array.isArray(items)) {
83
+ excludes2.push(...items);
84
+ } else {
85
+ excludes2.push(items);
86
+ }
64
87
  }
88
+ };
89
+ const decoratorConfig = config2.source.decorators;
90
+ const baseBabelConfig = isServer || isServiceWorker ? (0, import_node.getBabelConfigForNode)({
91
+ presetEnv: {
92
+ targets: [
93
+ "node >= 14"
94
+ ]
95
+ },
96
+ pluginDecorators: decoratorConfig
97
+ }) : (0, import_web.getBabelConfigForWeb)({
98
+ presetEnv: {
99
+ targets: browserslist,
100
+ useBuiltIns: (0, import_plugin_babel.getUseBuiltIns)(config2)
101
+ },
102
+ pluginDecorators: decoratorConfig
103
+ });
104
+ applyPluginImport(baseBabelConfig, config2.source.transformImport);
105
+ applyPluginLodash(baseBabelConfig, extraOptions.transformLodash);
106
+ (_baseBabelConfig_presets = baseBabelConfig.presets) === null || _baseBabelConfig_presets === void 0 ? void 0 : _baseBabelConfig_presets.push(getPresetReact(api.context.rootPath, isProd));
107
+ if (isProd) {
108
+ var _baseBabelConfig_plugins;
109
+ (_baseBabelConfig_plugins = baseBabelConfig.plugins) === null || _baseBabelConfig_plugins === void 0 ? void 0 : _baseBabelConfig_plugins.push([
110
+ require.resolve("babel-plugin-transform-react-remove-prop-types"),
111
+ {
112
+ removeImport: true
113
+ }
114
+ ]);
65
115
  }
66
- };
67
- const decoratorConfig = {
68
- version: config2.output.enableLatestDecorators ? "2018-09" : "legacy"
69
- };
70
- const baseBabelConfig = isServer || isServiceWorker ? (0, import_node.getBabelConfigForNode)({
71
- presetEnv: {
72
- targets: [
73
- "node >= 14"
74
- ]
75
- },
76
- pluginDecorators: decoratorConfig
77
- }) : (0, import_web.getBabelConfigForWeb)({
78
- presetEnv: {
79
- targets: browserslist,
80
- useBuiltIns: (0, import_plugin_babel.getUseBuiltIns)(config2)
81
- },
82
- pluginDecorators: decoratorConfig
83
- });
84
- applyPluginImport(baseBabelConfig, config2.source.transformImport);
85
- applyPluginLodash(baseBabelConfig, config2.performance.transformLodash);
86
- const presetReactOptions = {
87
- development: !isProd,
88
- // Will use the native built-in instead of trying to polyfill
89
- useBuiltIns: true,
90
- useSpread: false,
91
- runtime: isNewJsx ? "automatic" : "classic"
92
- };
93
- (_baseBabelConfig_presets = baseBabelConfig.presets) === null || _baseBabelConfig_presets === void 0 ? void 0 : _baseBabelConfig_presets.push([
94
- require.resolve("@babel/preset-react"),
95
- presetReactOptions
96
- ]);
97
- if (isProd) {
98
- var _baseBabelConfig_plugins;
99
- (_baseBabelConfig_plugins = baseBabelConfig.plugins) === null || _baseBabelConfig_plugins === void 0 ? void 0 : _baseBabelConfig_plugins.push([
100
- require.resolve("babel-plugin-transform-react-remove-prop-types"),
101
- {
102
- removeImport: true
116
+ const babelConfig = (0, import_shared.mergeChainedOptions)({
117
+ defaults: baseBabelConfig,
118
+ options: options === null || options === void 0 ? void 0 : options.babelLoaderOptions,
119
+ utils: {
120
+ ...(0, import_plugin_babel.getBabelUtils)(baseBabelConfig),
121
+ ...babelUtils
103
122
  }
104
- ]);
105
- }
106
- const babelConfig = (0, import_shared.mergeChainedOptions)({
107
- defaults: baseBabelConfig,
108
- options: options === null || options === void 0 ? void 0 : options.babelLoaderOptions,
109
- utils: {
110
- ...(0, import_plugin_babel.getBabelUtils)(baseBabelConfig),
111
- ...babelUtils
123
+ });
124
+ const finalOptions = {
125
+ babelrc: false,
126
+ configFile: false,
127
+ compact: isProd,
128
+ ...babelConfig
129
+ };
130
+ if (config2.output.charset === "utf8") {
131
+ finalOptions.generatorOpts = {
132
+ jsescOption: {
133
+ minimal: true
134
+ }
135
+ };
112
136
  }
113
- });
114
- const finalOptions = {
115
- babelrc: false,
116
- configFile: false,
117
- compact: isProd,
118
- ...babelConfig
119
- };
120
- if (config2.output.charset === "utf8") {
121
- finalOptions.generatorOpts = {
122
- jsescOption: {
123
- minimal: true
124
- }
137
+ return {
138
+ babelOptions: finalOptions,
139
+ includes: includes2,
140
+ excludes: excludes2
125
141
  };
126
- }
127
- return {
128
- babelOptions: finalOptions,
129
- includes: includes2,
130
- excludes: excludes2
131
142
  };
132
- };
133
- const { babelOptions, includes, excludes } = getBabelOptions(config);
134
- const rule = chain.module.rule(CHAIN_ID.RULE.JS);
135
- (0, import_shared.applyScriptCondition)({
136
- rule,
137
- config,
138
- context: api.context,
139
- includes,
140
- excludes
141
- });
142
- rule.test(import_shared.SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(require.resolve("babel-loader")).options(babelOptions);
143
- chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).mimetype({
144
- or: [
145
- "text/javascript",
146
- "application/javascript"
147
- ]
148
- }).use(CHAIN_ID.USE.BABEL).loader(require.resolve("babel-loader")).options((0, import_cloneDeep.default)(babelOptions));
143
+ const { babelOptions, includes, excludes } = getBabelOptions(config);
144
+ const rule = chain.module.rule(CHAIN_ID.RULE.JS);
145
+ (0, import_shared.applyScriptCondition)({
146
+ rule,
147
+ config,
148
+ context: api.context,
149
+ includes,
150
+ excludes
151
+ });
152
+ rule.test(import_shared.SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(require.resolve("babel-loader")).options(babelOptions);
153
+ chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).mimetype({
154
+ or: [
155
+ "text/javascript",
156
+ "application/javascript"
157
+ ]
158
+ }).resolve.set("fullySpecified", false).end().use(CHAIN_ID.USE.BABEL).loader(require.resolve("babel-loader")).options((0, import_cloneDeep.default)(babelOptions));
159
+ }
149
160
  });
150
161
  }
151
162
  });
@@ -181,5 +192,6 @@ function applyPluginImport(config, pluginImport) {
181
192
  }
182
193
  // Annotate the CommonJS export names for ESM import in node:
183
194
  0 && (module.exports = {
195
+ getPresetReact,
184
196
  pluginBabel
185
197
  });
@@ -31,9 +31,14 @@ __export(styledComponents_exports, {
31
31
  pluginStyledComponents: () => pluginStyledComponents
32
32
  });
33
33
  module.exports = __toCommonJS(styledComponents_exports);
34
+ var import_core = require("@rsbuild/core");
34
35
  var import_shared = require("@rsbuild/shared");
35
36
  const pluginStyledComponents = (userConfig = {}) => ({
36
37
  name: "uni-builder:styled-components",
38
+ pre: [
39
+ import_core.PLUGIN_SWC_NAME,
40
+ "uni-builder:babel"
41
+ ],
37
42
  setup(api) {
38
43
  api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd }) => {
39
44
  const isSSR = (0, import_shared.isServerTarget)(api.context.targets);
@@ -34,66 +34,78 @@ module.exports = __toCommonJS(tsLoader_exports);
34
34
  var import_shared = require("@rsbuild/shared");
35
35
  var import_plugin_babel = require("@rsbuild/plugin-babel");
36
36
  var import_web = require("@rsbuild/babel-preset/web");
37
+ var import_babel = require("./babel");
37
38
  const pluginTsLoader = (options, babelOptions) => {
38
39
  return {
39
40
  name: "uni-builder:ts-loader",
40
41
  pre: [
41
42
  "uni-builder:babel"
42
43
  ],
43
- post: [
44
- "uni-builder:react"
45
- ],
46
44
  setup(api) {
47
- api.modifyBundlerChain(async (chain, { target, CHAIN_ID }) => {
48
- const config = api.getNormalizedConfig();
49
- const { rootPath } = api.context;
50
- const browserslist = await (0, import_shared.getBrowserslistWithDefault)(rootPath, config, target);
51
- const baseBabelConfig = (0, import_web.getBabelConfigForWeb)({
52
- presetEnv: {
53
- targets: browserslist,
54
- useBuiltIns: (0, import_plugin_babel.getUseBuiltIns)(config)
55
- }
56
- });
57
- const babelUtils = (0, import_plugin_babel.getBabelUtils)(baseBabelConfig);
58
- const babelLoaderOptions = (0, import_shared.mergeChainedOptions)({
59
- defaults: baseBabelConfig,
60
- options: babelOptions,
61
- utils: babelUtils
62
- });
63
- const includes = [];
64
- const excludes = [];
65
- const tsLoaderUtils = {
66
- addIncludes(items) {
67
- includes.push(...(0, import_shared.castArray)(items));
68
- },
69
- addExcludes(items) {
70
- excludes.push(...(0, import_shared.castArray)(items));
71
- }
72
- };
73
- const tsLoaderDefaultOptions = {
74
- compilerOptions: {
75
- target: "esnext",
76
- module: "esnext"
77
- },
78
- transpileOnly: true,
79
- allowTsInNodeModules: true
80
- };
81
- const tsLoaderOptions = (0, import_shared.mergeChainedOptions)({
82
- defaults: tsLoaderDefaultOptions,
83
- // @ts-expect-error ts-loader has incorrect types for compilerOptions
84
- options,
85
- utils: tsLoaderUtils
86
- });
87
- const rule = chain.module.rule(CHAIN_ID.RULE.TS);
88
- (0, import_shared.applyScriptCondition)({
89
- rule,
90
- config,
91
- context: api.context,
92
- includes,
93
- excludes
94
- });
95
- chain.module.rule(CHAIN_ID.RULE.JS).test(import_shared.JS_REGEX);
96
- rule.test(import_shared.TS_REGEX).use(CHAIN_ID.USE.BABEL).loader(require.resolve("babel-loader")).options(babelLoaderOptions).end().use(CHAIN_ID.USE.TS).loader(require.resolve("ts-loader")).options(tsLoaderOptions);
45
+ api.modifyBundlerChain({
46
+ order: "pre",
47
+ handler: async (chain, { isProd, target, CHAIN_ID }) => {
48
+ var _baseBabelConfig_presets;
49
+ const config = api.getNormalizedConfig();
50
+ const { rootPath } = api.context;
51
+ const browserslist = await (0, import_shared.getBrowserslistWithDefault)(rootPath, config, target);
52
+ const baseBabelConfig = (0, import_web.getBabelConfigForWeb)({
53
+ presetEnv: {
54
+ targets: browserslist,
55
+ useBuiltIns: (0, import_plugin_babel.getUseBuiltIns)(config)
56
+ }
57
+ });
58
+ (_baseBabelConfig_presets = baseBabelConfig.presets) === null || _baseBabelConfig_presets === void 0 ? void 0 : _baseBabelConfig_presets.push((0, import_babel.getPresetReact)(api.context.rootPath, isProd));
59
+ const babelUtils = (0, import_plugin_babel.getBabelUtils)(baseBabelConfig);
60
+ const babelLoaderOptions = (0, import_shared.mergeChainedOptions)({
61
+ defaults: baseBabelConfig,
62
+ options: babelOptions,
63
+ utils: babelUtils
64
+ });
65
+ const includes = [];
66
+ const excludes = [];
67
+ const tsLoaderUtils = {
68
+ addIncludes(items) {
69
+ includes.push(...(0, import_shared.castArray)(items));
70
+ },
71
+ addExcludes(items) {
72
+ excludes.push(...(0, import_shared.castArray)(items));
73
+ }
74
+ };
75
+ const tsLoaderDefaultOptions = {
76
+ compilerOptions: {
77
+ target: "esnext",
78
+ module: "esnext"
79
+ },
80
+ transpileOnly: true,
81
+ allowTsInNodeModules: true
82
+ };
83
+ const tsLoaderOptions = (0, import_shared.mergeChainedOptions)({
84
+ defaults: tsLoaderDefaultOptions,
85
+ // @ts-expect-error ts-loader has incorrect types for compilerOptions
86
+ options,
87
+ utils: tsLoaderUtils
88
+ });
89
+ const rule = chain.module.rule(CHAIN_ID.RULE.TS);
90
+ (0, import_shared.applyScriptCondition)({
91
+ rule,
92
+ config,
93
+ context: api.context,
94
+ includes,
95
+ excludes
96
+ });
97
+ chain.module.rule(CHAIN_ID.RULE.JS).test(import_shared.JS_REGEX);
98
+ rule.test(import_shared.TS_REGEX).use(CHAIN_ID.USE.BABEL).loader(require.resolve("babel-loader")).options({
99
+ ...babelLoaderOptions,
100
+ // fix repeatedly insert babel plugin in some boundary cases
101
+ plugins: [
102
+ ...babelLoaderOptions.plugins || []
103
+ ],
104
+ presets: [
105
+ ...babelLoaderOptions.presets || []
106
+ ]
107
+ }).end().use(CHAIN_ID.USE.TS).loader(require.resolve("ts-loader")).options(tsLoaderOptions);
108
+ }
97
109
  });
98
110
  }
99
111
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modern-js/uni-builder",
3
- "version": "2.46.0",
3
+ "version": "2.47.0",
4
4
  "description": "Unified builder for Modern.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,23 +26,23 @@
26
26
  "@babel/preset-react": "^7.22.15",
27
27
  "@babel/types": "^7.23.0",
28
28
  "@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
29
- "@rsbuild/babel-preset": "0.3.3",
30
- "@rsbuild/core": "0.3.3",
31
- "@rsbuild/plugin-assets-retry": "0.3.3",
32
- "@rsbuild/plugin-babel": "0.3.3",
33
- "@rsbuild/plugin-check-syntax": "0.3.3",
34
- "@rsbuild/plugin-css-minimizer": "0.3.3",
35
- "@rsbuild/plugin-pug": "0.3.3",
36
- "@rsbuild/plugin-react": "0.3.3",
37
- "@rsbuild/plugin-rem": "0.3.3",
38
- "@rsbuild/plugin-source-build": "0.3.3",
39
- "@rsbuild/plugin-styled-components": "0.3.3",
40
- "@rsbuild/plugin-svgr": "0.3.3",
41
- "@rsbuild/plugin-type-check": "0.3.3",
42
- "@rsbuild/plugin-toml": "0.3.3",
43
- "@rsbuild/plugin-yaml": "0.3.3",
44
- "@rsbuild/shared": "0.3.3",
45
- "@rsbuild/webpack": "0.3.3",
29
+ "@rsbuild/babel-preset": "0.4.4",
30
+ "@rsbuild/core": "0.4.4",
31
+ "@rsbuild/plugin-assets-retry": "0.4.4",
32
+ "@rsbuild/plugin-babel": "0.4.4",
33
+ "@rsbuild/plugin-check-syntax": "0.4.4",
34
+ "@rsbuild/plugin-css-minimizer": "0.4.4",
35
+ "@rsbuild/plugin-pug": "0.4.4",
36
+ "@rsbuild/plugin-react": "0.4.4",
37
+ "@rsbuild/plugin-rem": "0.4.4",
38
+ "@rsbuild/plugin-source-build": "0.4.4",
39
+ "@rsbuild/plugin-styled-components": "0.4.4",
40
+ "@rsbuild/plugin-svgr": "0.4.4",
41
+ "@rsbuild/plugin-type-check": "0.4.4",
42
+ "@rsbuild/plugin-toml": "0.4.4",
43
+ "@rsbuild/plugin-yaml": "0.4.4",
44
+ "@rsbuild/shared": "0.4.4",
45
+ "@rsbuild/webpack": "0.4.4",
46
46
  "@swc/helpers": "0.5.3",
47
47
  "babel-loader": "9.1.3",
48
48
  "babel-plugin-import": "1.13.5",
@@ -53,6 +53,7 @@
53
53
  "html-webpack-plugin": "5.5.3",
54
54
  "lodash": "^4.17.21",
55
55
  "postcss-custom-properties": "13.1.5",
56
+ "postcss-flexbugs-fixes": "5.0.2",
56
57
  "postcss-font-variant": "5.0.0",
57
58
  "postcss-initial": "4.0.1",
58
59
  "postcss-media-minmax": "5.0.0",
@@ -64,19 +65,18 @@
64
65
  "webpack": "^5.89.0",
65
66
  "webpack-manifest-plugin": "5.0.0",
66
67
  "webpack-subresource-integrity": "5.1.0",
67
- "@modern-js/utils": "2.46.0",
68
- "@modern-js/server": "2.46.0",
69
- "@modern-js/prod-server": "2.46.0"
68
+ "@modern-js/utils": "2.47.0",
69
+ "@modern-js/server": "2.47.0",
70
+ "@modern-js/prod-server": "2.47.0"
70
71
  },
71
72
  "devDependencies": {
72
- "@rsbuild/plugin-swc": "0.3.3",
73
+ "@rsbuild/plugin-swc": "0.4.4",
73
74
  "@types/lodash": "^4.14.202",
74
75
  "react": "^18.2.0",
75
76
  "react-dom": "^18.2.0",
76
77
  "typescript": "^5.3.0",
77
- "@modern-js/builder-plugin-node-polyfill": "2.46.0",
78
- "@scripts/vitest-config": "2.46.0",
79
- "@scripts/build": "2.46.0"
78
+ "@scripts/build": "2.47.0",
79
+ "@scripts/vitest-config": "2.47.0"
80
80
  },
81
81
  "publishConfig": {
82
82
  "access": "public",