@modern-js/uni-builder 0.0.0-nightly-20240217170621 → 0.0.0-nightly-20240218170609
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.
- package/dist/rspack/plugins/babel-post.js +11 -9
- package/dist/shared/parseCommonConfig.js +15 -3
- package/dist/shared/plugins/antd.d.ts +2 -0
- package/dist/shared/plugins/antd.js +69 -0
- package/dist/shared/plugins/arco.d.ts +2 -0
- package/dist/shared/plugins/arco.js +61 -0
- package/dist/shared/plugins/postcssLegacy.js +1 -0
- package/dist/shared/plugins/splitChunk.js +5 -4
- package/dist/types.d.ts +17 -0
- package/dist/webpack/index.js +4 -1
- package/dist/webpack/plugins/babel.d.ts +8 -1
- package/dist/webpack/plugins/babel.js +97 -90
- package/dist/webpack/plugins/tsLoader.js +64 -64
- package/package.json +26 -25
|
@@ -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(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
});
|
|
@@ -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)) {
|
|
@@ -105,7 +107,7 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
105
107
|
var _newDevServerConfig_devMiddleware, _uniBuilderConfig_output, _uniBuilderConfig_tools;
|
|
106
108
|
var _output, _output_distPath, _output_distPath1, _output1, _extraConfig, _html, _extraConfig1;
|
|
107
109
|
const { cwd, frameworkConfigPath, entry, target } = options;
|
|
108
|
-
const { plugins: [...plugins] = [], performance: { ...performanceConfig } = {}, output: { 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;
|
|
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;
|
|
109
111
|
const rsbuildConfig = {
|
|
110
112
|
plugins,
|
|
111
113
|
output: outputConfig,
|
|
@@ -119,7 +121,12 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
119
121
|
dev: devConfig,
|
|
120
122
|
security: securityConfig
|
|
121
123
|
};
|
|
122
|
-
const { dev = {}, html = {}, output = {} } = rsbuildConfig;
|
|
124
|
+
const { dev = {}, html = {}, output = {}, source = {} } = rsbuildConfig;
|
|
125
|
+
if (enableLatestDecorators) {
|
|
126
|
+
source.decorators = {
|
|
127
|
+
version: "2022-03"
|
|
128
|
+
};
|
|
129
|
+
}
|
|
123
130
|
if (cssModuleLocalIdentName) {
|
|
124
131
|
var _output2;
|
|
125
132
|
(_output2 = output).cssModules || (_output2.cssModules = {});
|
|
@@ -162,6 +169,9 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
162
169
|
if (enableInlineStyles) {
|
|
163
170
|
output.inlineStyles = enableInlineStyles;
|
|
164
171
|
}
|
|
172
|
+
if (disableFilenameHash !== void 0) {
|
|
173
|
+
output.filenameHash = !disableFilenameHash;
|
|
174
|
+
}
|
|
165
175
|
const extraConfig = {};
|
|
166
176
|
(_extraConfig = extraConfig).html || (_extraConfig.html = {});
|
|
167
177
|
extraConfig.html.outputStructure = disableHtmlFolder ? "flat" : "nested";
|
|
@@ -248,7 +258,9 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
248
258
|
}),
|
|
249
259
|
(0, import_emitRouteFile.pluginEmitRouteFile)(),
|
|
250
260
|
(0, import_plugin_toml.pluginToml)(),
|
|
251
|
-
(0, import_plugin_yaml.pluginYaml)()
|
|
261
|
+
(0, import_plugin_yaml.pluginYaml)(),
|
|
262
|
+
(0, import_antd.pluginAntd)(),
|
|
263
|
+
(0, import_arco.pluginArco)()
|
|
252
264
|
];
|
|
253
265
|
if (checkSyntax) {
|
|
254
266
|
const { pluginCheckSyntax } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-check-syntax")));
|
|
@@ -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,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
|
+
});
|
|
@@ -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,
|
|
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,
|
|
41
|
+
if ((0, import_utils.isPackageInstalled)("antd", rootPath)) {
|
|
41
42
|
groups.antd = [
|
|
42
43
|
"antd"
|
|
43
44
|
];
|
|
44
45
|
}
|
|
45
|
-
if ((0,
|
|
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,
|
|
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
|
@@ -122,6 +122,14 @@ export type UniBuilderExtraConfig = {
|
|
|
122
122
|
resolveExtensionPrefix?: string | Partial<Record<RsbuildTarget, string>>;
|
|
123
123
|
};
|
|
124
124
|
output?: {
|
|
125
|
+
/**
|
|
126
|
+
* @deprecated use `output.filenameHash` instead
|
|
127
|
+
*/
|
|
128
|
+
disableFilenameHash?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* @deprecated use `source.decorators` instead
|
|
131
|
+
*/
|
|
132
|
+
enableLatestDecorators?: boolean;
|
|
125
133
|
/**
|
|
126
134
|
* @deprecated use `output.cssModules.localIdentName` instead
|
|
127
135
|
*/
|
|
@@ -212,6 +220,15 @@ export type UniBuilderExtraConfig = {
|
|
|
212
220
|
*/
|
|
213
221
|
templateParametersByEntries?: Record<string, Record<string, unknown>>;
|
|
214
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
|
+
};
|
|
215
232
|
security?: {
|
|
216
233
|
/**
|
|
217
234
|
* Adding an integrity attribute (`integrity`) to sub-resources introduced by HTML allows the browser to
|
package/dist/webpack/index.js
CHANGED
|
@@ -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,9 +1,16 @@
|
|
|
1
1
|
import { type RsbuildPlugin } from '@rsbuild/shared';
|
|
2
2
|
import { type PluginBabelOptions } from '@rsbuild/plugin-babel';
|
|
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
|
+
*/
|
|
3
8
|
export declare const getPresetReact: (rootPath: string, isProd: boolean) => (string | {
|
|
4
9
|
development: boolean;
|
|
5
10
|
useBuiltIns: boolean;
|
|
6
11
|
useSpread: boolean;
|
|
7
12
|
runtime: string;
|
|
8
13
|
})[];
|
|
9
|
-
export declare const pluginBabel: (options
|
|
14
|
+
export declare const pluginBabel: (options: PluginBabelOptions, extraOptions: {
|
|
15
|
+
transformLodash: boolean;
|
|
16
|
+
}) => RsbuildPlugin;
|
|
@@ -52,104 +52,111 @@ const getPresetReact = (rootPath, isProd) => {
|
|
|
52
52
|
presetReactOptions
|
|
53
53
|
];
|
|
54
54
|
};
|
|
55
|
-
const pluginBabel = (options) => ({
|
|
55
|
+
const pluginBabel = (options, extraOptions) => ({
|
|
56
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
|
+
],
|
|
57
63
|
setup(api) {
|
|
58
|
-
api.modifyBundlerChain(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
+
}
|
|
78
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
|
+
]);
|
|
79
115
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
targets: [
|
|
87
|
-
"node >= 14"
|
|
88
|
-
]
|
|
89
|
-
},
|
|
90
|
-
pluginDecorators: decoratorConfig
|
|
91
|
-
}) : (0, import_web.getBabelConfigForWeb)({
|
|
92
|
-
presetEnv: {
|
|
93
|
-
targets: browserslist,
|
|
94
|
-
useBuiltIns: (0, import_plugin_babel.getUseBuiltIns)(config2)
|
|
95
|
-
},
|
|
96
|
-
pluginDecorators: decoratorConfig
|
|
97
|
-
});
|
|
98
|
-
applyPluginImport(baseBabelConfig, config2.source.transformImport);
|
|
99
|
-
applyPluginLodash(baseBabelConfig, config2.performance.transformLodash);
|
|
100
|
-
(_baseBabelConfig_presets = baseBabelConfig.presets) === null || _baseBabelConfig_presets === void 0 ? void 0 : _baseBabelConfig_presets.push(getPresetReact(api.context.rootPath, isProd));
|
|
101
|
-
if (isProd) {
|
|
102
|
-
var _baseBabelConfig_plugins;
|
|
103
|
-
(_baseBabelConfig_plugins = baseBabelConfig.plugins) === null || _baseBabelConfig_plugins === void 0 ? void 0 : _baseBabelConfig_plugins.push([
|
|
104
|
-
require.resolve("babel-plugin-transform-react-remove-prop-types"),
|
|
105
|
-
{
|
|
106
|
-
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
|
|
107
122
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
+
};
|
|
116
136
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
compact: isProd,
|
|
122
|
-
...babelConfig
|
|
123
|
-
};
|
|
124
|
-
if (config2.output.charset === "utf8") {
|
|
125
|
-
finalOptions.generatorOpts = {
|
|
126
|
-
jsescOption: {
|
|
127
|
-
minimal: true
|
|
128
|
-
}
|
|
137
|
+
return {
|
|
138
|
+
babelOptions: finalOptions,
|
|
139
|
+
includes: includes2,
|
|
140
|
+
excludes: excludes2
|
|
129
141
|
};
|
|
130
|
-
}
|
|
131
|
-
return {
|
|
132
|
-
babelOptions: finalOptions,
|
|
133
|
-
includes: includes2,
|
|
134
|
-
excludes: excludes2
|
|
135
142
|
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
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
|
+
}
|
|
153
160
|
});
|
|
154
161
|
}
|
|
155
162
|
});
|
|
@@ -41,71 +41,71 @@ const pluginTsLoader = (options, babelOptions) => {
|
|
|
41
41
|
pre: [
|
|
42
42
|
"uni-builder:babel"
|
|
43
43
|
],
|
|
44
|
-
post: [
|
|
45
|
-
"uni-builder:react"
|
|
46
|
-
],
|
|
47
44
|
setup(api) {
|
|
48
|
-
api.modifyBundlerChain(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
rule
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
+
}
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
111
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/uni-builder",
|
|
3
|
-
"version": "0.0.0-nightly-
|
|
3
|
+
"version": "0.0.0-nightly-20240218170609",
|
|
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
|
|
30
|
-
"@rsbuild/core": "0.3
|
|
31
|
-
"@rsbuild/plugin-assets-retry": "0.3
|
|
32
|
-
"@rsbuild/plugin-babel": "0.3
|
|
33
|
-
"@rsbuild/plugin-check-syntax": "0.3
|
|
34
|
-
"@rsbuild/plugin-css-minimizer": "0.3
|
|
35
|
-
"@rsbuild/plugin-pug": "0.3
|
|
36
|
-
"@rsbuild/plugin-react": "0.3
|
|
37
|
-
"@rsbuild/plugin-rem": "0.3
|
|
38
|
-
"@rsbuild/plugin-source-build": "0.3
|
|
39
|
-
"@rsbuild/plugin-styled-components": "0.3
|
|
40
|
-
"@rsbuild/plugin-svgr": "0.3
|
|
41
|
-
"@rsbuild/plugin-type-check": "0.3
|
|
42
|
-
"@rsbuild/plugin-toml": "0.3
|
|
43
|
-
"@rsbuild/plugin-yaml": "0.3
|
|
44
|
-
"@rsbuild/shared": "0.3
|
|
45
|
-
"@rsbuild/webpack": "0.3
|
|
29
|
+
"@rsbuild/babel-preset": "0.4.3",
|
|
30
|
+
"@rsbuild/core": "0.4.3",
|
|
31
|
+
"@rsbuild/plugin-assets-retry": "0.4.3",
|
|
32
|
+
"@rsbuild/plugin-babel": "0.4.3",
|
|
33
|
+
"@rsbuild/plugin-check-syntax": "0.4.3",
|
|
34
|
+
"@rsbuild/plugin-css-minimizer": "0.4.3",
|
|
35
|
+
"@rsbuild/plugin-pug": "0.4.3",
|
|
36
|
+
"@rsbuild/plugin-react": "0.4.3",
|
|
37
|
+
"@rsbuild/plugin-rem": "0.4.3",
|
|
38
|
+
"@rsbuild/plugin-source-build": "0.4.3",
|
|
39
|
+
"@rsbuild/plugin-styled-components": "0.4.3",
|
|
40
|
+
"@rsbuild/plugin-svgr": "0.4.3",
|
|
41
|
+
"@rsbuild/plugin-type-check": "0.4.3",
|
|
42
|
+
"@rsbuild/plugin-toml": "0.4.3",
|
|
43
|
+
"@rsbuild/plugin-yaml": "0.4.3",
|
|
44
|
+
"@rsbuild/shared": "0.4.3",
|
|
45
|
+
"@rsbuild/webpack": "0.4.3",
|
|
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,19 @@
|
|
|
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": "0.0.0-nightly-
|
|
68
|
-
"@modern-js/server": "0.0.0-nightly-
|
|
69
|
-
"@modern-js/
|
|
68
|
+
"@modern-js/utils": "0.0.0-nightly-20240218170609",
|
|
69
|
+
"@modern-js/prod-server": "0.0.0-nightly-20240218170609",
|
|
70
|
+
"@modern-js/server": "0.0.0-nightly-20240218170609"
|
|
70
71
|
},
|
|
71
72
|
"devDependencies": {
|
|
72
|
-
"@rsbuild/plugin-swc": "0.3
|
|
73
|
+
"@rsbuild/plugin-swc": "0.4.3",
|
|
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
|
-
"@
|
|
78
|
-
"@
|
|
79
|
-
"@scripts/
|
|
78
|
+
"@scripts/build": "0.0.0-nightly-20240218170609",
|
|
79
|
+
"@modern-js/builder-plugin-node-polyfill": "0.0.0-nightly-20240218170609",
|
|
80
|
+
"@scripts/vitest-config": "0.0.0-nightly-20240218170609"
|
|
80
81
|
},
|
|
81
82
|
"publishConfig": {
|
|
82
83
|
"access": "public",
|