@modern-js/uni-builder 2.54.6 → 2.55.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.
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -0
- package/dist/rspack/plugins/babel-post.d.ts +1 -1
- package/dist/shared/devServer.d.ts +4 -3
- package/dist/shared/devServer.js +4 -4
- package/dist/shared/getCssSupport.js +1 -1
- package/dist/shared/manifest.d.ts +1 -1
- package/dist/shared/parseCommonConfig.js +6 -37
- package/dist/shared/plugins/antd.d.ts +1 -1
- package/dist/shared/plugins/arco.d.ts +1 -1
- package/dist/shared/plugins/devtools.d.ts +1 -1
- package/dist/shared/plugins/emitRouteFile.d.ts +1 -1
- package/dist/shared/plugins/emitRouteFile.js +6 -6
- package/dist/shared/plugins/extensionPrefix.d.ts +1 -2
- package/dist/shared/plugins/fallback.js +13 -20
- package/dist/shared/plugins/frameworkConfig.js +12 -2
- package/dist/shared/plugins/mainFields.d.ts +1 -2
- package/dist/shared/plugins/postcssLegacy.js +2 -2
- package/dist/shared/utils.d.ts +20 -1
- package/dist/shared/utils.js +95 -0
- package/dist/types.d.ts +28 -8
- package/dist/webpack/ModuleScopePlugin.js +14 -4
- package/dist/webpack/plugins/babel.d.ts +1 -1
- package/dist/webpack/plugins/babel.js +4 -4
- package/dist/webpack/plugins/lazyCompilation.d.ts +1 -2
- package/dist/webpack/plugins/minimize.d.ts +1 -1
- package/dist/webpack/plugins/minimize.js +4 -5
- package/dist/webpack/plugins/moduleScopes.d.ts +1 -2
- package/dist/webpack/plugins/react.js +2 -2
- package/dist/webpack/plugins/styledComponents.d.ts +1 -2
- package/dist/webpack/plugins/tsLoader.d.ts +4 -1
- package/dist/webpack/plugins/tsLoader.js +5 -6
- package/package.json +9 -6
package/dist/index.d.ts
CHANGED
|
@@ -4,10 +4,10 @@ import type { CreateUniBuilderOptions } from './types';
|
|
|
4
4
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
5
5
|
export { HtmlWebpackPlugin };
|
|
6
6
|
export type { CreateUniBuilderOptions, UniBuilderInstance, UniBuilderWebpackInstance, };
|
|
7
|
-
export type {
|
|
8
|
-
export type { UniBuilderConfig, UniBuilderPlugin } from './types';
|
|
7
|
+
export type { CacheGroup } from '@rsbuild/shared';
|
|
8
|
+
export type { UniBuilderConfig, UniBuilderPlugin, BundlerType, MetaOptions, Stats, MultiStats, RspackConfig, } from './types';
|
|
9
9
|
export type { StartDevServerOptions } from './shared/devServer';
|
|
10
10
|
export declare function createUniBuilder(options: CreateUniBuilderOptions): Promise<UniBuilderInstance>;
|
|
11
|
-
export { logger, type Rspack, type RsbuildContext, type RsbuildConfig, } from '@rsbuild/core';
|
|
11
|
+
export { logger, type ConfigChain, type RsbuildPlugin, type ChainIdentifier, type RspackChain, type Rspack, type RsbuildContext, type RsbuildConfig, type RsbuildTarget, type NormalizedConfig, } from '@rsbuild/core';
|
|
12
12
|
export type { webpack, WebpackConfig } from '@rsbuild/webpack';
|
|
13
|
-
export { RUNTIME_CHUNK_NAME } from './shared/utils';
|
|
13
|
+
export { RUNTIME_CHUNK_NAME, isHtmlDisabled, castArray } from './shared/utils';
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,9 @@ var src_exports = {};
|
|
|
30
30
|
__export(src_exports, {
|
|
31
31
|
HtmlWebpackPlugin: () => import_html_webpack_plugin.default,
|
|
32
32
|
RUNTIME_CHUNK_NAME: () => import_utils.RUNTIME_CHUNK_NAME,
|
|
33
|
+
castArray: () => import_utils.castArray,
|
|
33
34
|
createUniBuilder: () => createUniBuilder,
|
|
35
|
+
isHtmlDisabled: () => import_utils.isHtmlDisabled,
|
|
34
36
|
logger: () => import_core.logger
|
|
35
37
|
});
|
|
36
38
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -46,6 +48,8 @@ async function createUniBuilder(options) {
|
|
|
46
48
|
0 && (module.exports = {
|
|
47
49
|
HtmlWebpackPlugin,
|
|
48
50
|
RUNTIME_CHUNK_NAME,
|
|
51
|
+
castArray,
|
|
49
52
|
createUniBuilder,
|
|
53
|
+
isHtmlDisabled,
|
|
50
54
|
logger
|
|
51
55
|
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
3
|
-
import { type RsbuildInstance } from '@rsbuild/core';
|
|
2
|
+
import { type RsbuildInstance, type DevConfig, type ServerConfig, type Rspack } from '@rsbuild/core';
|
|
4
3
|
import type { ModernDevServerOptions } from '@modern-js/server';
|
|
5
4
|
import type { Server } from 'node:http';
|
|
6
5
|
import { type ApplyPlugins } from '@modern-js/prod-server';
|
|
@@ -12,7 +11,9 @@ export declare const transformToRsbuildServerOptions: (dev: NonNullable<UniBuild
|
|
|
12
11
|
dev: DevConfig;
|
|
13
12
|
server: ServerConfig;
|
|
14
13
|
};
|
|
15
|
-
export type StartDevServerOptions =
|
|
14
|
+
export type StartDevServerOptions = {
|
|
15
|
+
compiler?: Rspack.Compiler | Rspack.MultiCompiler;
|
|
16
|
+
getPortSilently?: boolean;
|
|
16
17
|
apiOnly?: boolean;
|
|
17
18
|
serverOptions?: ServerOptions;
|
|
18
19
|
applyPlugins?: ApplyPlugins;
|
package/dist/shared/devServer.js
CHANGED
|
@@ -32,7 +32,7 @@ __export(devServer_exports, {
|
|
|
32
32
|
transformToRsbuildServerOptions: () => transformToRsbuildServerOptions
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(devServer_exports);
|
|
35
|
-
var
|
|
35
|
+
var import_ts_deepmerge = require("ts-deepmerge");
|
|
36
36
|
var import_utils = require("@modern-js/utils");
|
|
37
37
|
var import_core = require("@rsbuild/core");
|
|
38
38
|
var import_prod_server = require("@modern-js/prod-server");
|
|
@@ -73,7 +73,7 @@ const transformToRsbuildServerOptions = (dev, devServer) => {
|
|
|
73
73
|
overlay: false,
|
|
74
74
|
...devConfig.client || {}
|
|
75
75
|
}
|
|
76
|
-
}, devServer, {},
|
|
76
|
+
}, devServer, {}, import_ts_deepmerge.merge);
|
|
77
77
|
const rsbuildDev = {
|
|
78
78
|
...devConfig,
|
|
79
79
|
writeToDisk: (_newDevServerConfig_devMiddleware = newDevServerConfig.devMiddleware) === null || _newDevServerConfig_devMiddleware === void 0 ? void 0 : _newDevServerConfig_devMiddleware.writeToDisk,
|
|
@@ -95,7 +95,7 @@ const transformToRsbuildServerOptions = (dev, devServer) => {
|
|
|
95
95
|
} else if (newDevServerConfig.setupMiddlewares) {
|
|
96
96
|
rsbuildDev.setupMiddlewares = newDevServerConfig.setupMiddlewares;
|
|
97
97
|
}
|
|
98
|
-
const server = (0,
|
|
98
|
+
const server = (0, import_utils.isProd)() ? {
|
|
99
99
|
publicDir: false,
|
|
100
100
|
htmlFallback: false,
|
|
101
101
|
printUrls: false
|
|
@@ -118,7 +118,7 @@ const transformToRsbuildServerOptions = (dev, devServer) => {
|
|
|
118
118
|
};
|
|
119
119
|
const getDevServerOptions = async ({ builderConfig, serverOptions }) => {
|
|
120
120
|
const defaultConfig = getServerOptions(builderConfig);
|
|
121
|
-
const config = serverOptions.config ? (0,
|
|
121
|
+
const config = serverOptions.config ? (0, import_ts_deepmerge.merge)(defaultConfig, serverOptions.config) : defaultConfig;
|
|
122
122
|
return {
|
|
123
123
|
config
|
|
124
124
|
};
|
|
@@ -31,7 +31,7 @@ __export(getCssSupport_exports, {
|
|
|
31
31
|
getCssSupport: () => getCssSupport
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(getCssSupport_exports);
|
|
34
|
-
var import_browserslist = __toESM(require("
|
|
34
|
+
var import_browserslist = __toESM(require("browserslist"));
|
|
35
35
|
const CSS_FEATURES_BROWSER = {
|
|
36
36
|
customProperties: {
|
|
37
37
|
and_chr: "49",
|
|
@@ -32,8 +32,8 @@ __export(parseCommonConfig_exports, {
|
|
|
32
32
|
parseCommonConfig: () => parseCommonConfig
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(parseCommonConfig_exports);
|
|
35
|
-
var import_shared = require("@rsbuild/shared");
|
|
36
35
|
var import_core = require("@rsbuild/core");
|
|
36
|
+
var import_utils = require("@modern-js/utils");
|
|
37
37
|
var import_plugin_toml = require("@rsbuild/plugin-toml");
|
|
38
38
|
var import_plugin_yaml = require("@rsbuild/plugin-yaml");
|
|
39
39
|
var import_plugin_react = require("@rsbuild/plugin-react");
|
|
@@ -50,10 +50,11 @@ var import_arco = require("./plugins/arco");
|
|
|
50
50
|
var import_plugin_sass = require("@rsbuild/plugin-sass");
|
|
51
51
|
var import_plugin_less = require("@rsbuild/plugin-less");
|
|
52
52
|
var import_devServer = require("./devServer");
|
|
53
|
+
var import_utils2 = require("./utils");
|
|
53
54
|
const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
|
|
54
55
|
const GLOBAL_CSS_REGEX = /\.global\.\w+$/;
|
|
55
56
|
const isLooseCssModules = (path) => {
|
|
56
|
-
if (
|
|
57
|
+
if (import_utils2.NODE_MODULES_REGEX.test(path)) {
|
|
57
58
|
return CSS_MODULES_REGEX.test(path);
|
|
58
59
|
}
|
|
59
60
|
return !GLOBAL_CSS_REGEX.test(path);
|
|
@@ -66,38 +67,6 @@ function removeUndefinedKey(obj) {
|
|
|
66
67
|
});
|
|
67
68
|
return obj;
|
|
68
69
|
}
|
|
69
|
-
const DEFAULT_WEB_BROWSERSLIST = [
|
|
70
|
-
"> 0.01%",
|
|
71
|
-
"not dead",
|
|
72
|
-
"not op_mini all"
|
|
73
|
-
];
|
|
74
|
-
const DEFAULT_BROWSERSLIST = {
|
|
75
|
-
web: DEFAULT_WEB_BROWSERSLIST,
|
|
76
|
-
node: [
|
|
77
|
-
"node >= 14"
|
|
78
|
-
],
|
|
79
|
-
"web-worker": DEFAULT_WEB_BROWSERSLIST,
|
|
80
|
-
"service-worker": DEFAULT_WEB_BROWSERSLIST
|
|
81
|
-
};
|
|
82
|
-
async function getBrowserslistWithDefault(path, config, target) {
|
|
83
|
-
const { overrideBrowserslist: overrides = {} } = (config === null || config === void 0 ? void 0 : config.output) || {};
|
|
84
|
-
if (target === "web" || target === "web-worker") {
|
|
85
|
-
if (Array.isArray(overrides)) {
|
|
86
|
-
return overrides;
|
|
87
|
-
}
|
|
88
|
-
if (overrides[target]) {
|
|
89
|
-
return overrides[target];
|
|
90
|
-
}
|
|
91
|
-
const browserslistrc = await (0, import_shared.getBrowserslist)(path);
|
|
92
|
-
if (browserslistrc) {
|
|
93
|
-
return browserslistrc;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
if (!Array.isArray(overrides) && overrides[target]) {
|
|
97
|
-
return overrides[target];
|
|
98
|
-
}
|
|
99
|
-
return DEFAULT_BROWSERSLIST[target];
|
|
100
|
-
}
|
|
101
70
|
const isUseCssSourceMap = (disableSourceMap = {}) => {
|
|
102
71
|
if (typeof disableSourceMap === "boolean") {
|
|
103
72
|
return !disableSourceMap;
|
|
@@ -174,7 +143,7 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
174
143
|
output.targets = targets;
|
|
175
144
|
const overrideBrowserslist = {};
|
|
176
145
|
for (const target2 of targets) {
|
|
177
|
-
overrideBrowserslist[target2] = await getBrowserslistWithDefault(cwd, uniBuilderConfig, target2);
|
|
146
|
+
overrideBrowserslist[target2] = await (0, import_utils2.getBrowserslistWithDefault)(cwd, uniBuilderConfig, target2);
|
|
178
147
|
}
|
|
179
148
|
output.overrideBrowserslist = overrideBrowserslist;
|
|
180
149
|
if (enableInlineStyles) {
|
|
@@ -215,10 +184,10 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
215
184
|
if (tagsByEntries) {
|
|
216
185
|
extraConfig.html.tags = [
|
|
217
186
|
(tags2, utils) => {
|
|
218
|
-
const entryTags = (0,
|
|
187
|
+
const entryTags = (0, import_utils2.castArray)(tagsByEntries[utils.entryName]);
|
|
219
188
|
const handlers = [];
|
|
220
189
|
for (const tag of entryTags) {
|
|
221
|
-
if ((0,
|
|
190
|
+
if ((0, import_utils.isFunction)(tag)) {
|
|
222
191
|
handlers.push(tag);
|
|
223
192
|
} else {
|
|
224
193
|
tags2.push(tag);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type RsbuildPlugin } from '@rsbuild/
|
|
1
|
+
import { type RsbuildPlugin } from '@rsbuild/core';
|
|
2
2
|
export declare const pluginAntd: () => RsbuildPlugin;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type RsbuildPlugin } from '@rsbuild/
|
|
1
|
+
import { type RsbuildPlugin } from '@rsbuild/core';
|
|
2
2
|
export declare const pluginArco: () => RsbuildPlugin;
|
|
@@ -32,17 +32,17 @@ __export(emitRouteFile_exports, {
|
|
|
32
32
|
pluginEmitRouteFile: () => pluginEmitRouteFile
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(emitRouteFile_exports);
|
|
35
|
-
var
|
|
36
|
-
var
|
|
35
|
+
var import_node_path = require("node:path");
|
|
36
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
37
37
|
async function isFileExists(file) {
|
|
38
|
-
return
|
|
38
|
+
return import_node_fs.default.promises.access(file, import_node_fs.default.constants.F_OK).then(() => true).catch(() => false);
|
|
39
39
|
}
|
|
40
40
|
const pluginEmitRouteFile = () => ({
|
|
41
41
|
name: "uni-builder:emit-route-file",
|
|
42
42
|
setup(api) {
|
|
43
43
|
api.onBeforeStartDevServer(async () => {
|
|
44
|
-
const { fs, ROUTE_SPEC_FILE } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
45
|
-
const routeFilePath = (0,
|
|
44
|
+
const { fs: fs2, ROUTE_SPEC_FILE } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
|
|
45
|
+
const routeFilePath = (0, import_node_path.join)(api.context.distPath, ROUTE_SPEC_FILE);
|
|
46
46
|
const htmlPaths = api.getHTMLPaths();
|
|
47
47
|
const routesInfo = Object.entries(htmlPaths).map(([entryName, filename], index) => ({
|
|
48
48
|
urlPath: index === 0 ? "/" : `/${entryName}`,
|
|
@@ -51,7 +51,7 @@ const pluginEmitRouteFile = () => ({
|
|
|
51
51
|
isSPA: true
|
|
52
52
|
}));
|
|
53
53
|
if (!await isFileExists(routeFilePath) && routesInfo.length) {
|
|
54
|
-
await
|
|
54
|
+
await fs2.outputFile(routeFilePath, JSON.stringify({
|
|
55
55
|
routes: routesInfo
|
|
56
56
|
}, null, 2));
|
|
57
57
|
}
|
|
@@ -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
|
-
|
|
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
|
-
|
|
75
|
-
api.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
assetModuleFilename: (0, import_path.join)(distDir, mediaFilename)
|
|
83
|
-
});
|
|
73
|
+
api.modifyBundlerChain((chain) => {
|
|
74
|
+
const rsbuildConfig = api.getNormalizedConfig();
|
|
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
|
|
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
|
-
(
|
|
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
|
|
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 (!
|
|
39
|
+
if (!import_node_fs.default.existsSync(configPath)) {
|
|
30
40
|
return;
|
|
31
41
|
}
|
|
32
42
|
const cache = chain.get("cache");
|
|
@@ -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;
|
|
@@ -21,7 +21,7 @@ __export(postcssLegacy_exports, {
|
|
|
21
21
|
pluginPostcssLegacy: () => pluginPostcssLegacy
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(postcssLegacy_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_utils = require("@modern-js/utils");
|
|
25
25
|
var import_getCssSupport = require("../getCssSupport");
|
|
26
26
|
const pluginPostcssLegacy = (webBrowserslist) => ({
|
|
27
27
|
name: "uni-builder:postcss-plugins",
|
|
@@ -30,7 +30,7 @@ const pluginPostcssLegacy = (webBrowserslist) => ({
|
|
|
30
30
|
var _config_output;
|
|
31
31
|
const cssSupport = (0, import_getCssSupport.getCssSupport)(webBrowserslist);
|
|
32
32
|
const enableExtractCSS = !((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.injectStyles);
|
|
33
|
-
const enableCssMinify = !enableExtractCSS &&
|
|
33
|
+
const enableCssMinify = !enableExtractCSS && import_utils.isProd;
|
|
34
34
|
const plugins = [
|
|
35
35
|
require("postcss-flexbugs-fixes"),
|
|
36
36
|
!cssSupport.customProperties && require("postcss-custom-properties"),
|
package/dist/shared/utils.d.ts
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
|
-
import type { RsbuildTarget, NormalizedConfig } from '@rsbuild/core';
|
|
1
|
+
import type { RsbuildTarget, RspackChain, RsbuildContext, NormalizedConfig } from '@rsbuild/core';
|
|
2
|
+
import { OverrideBrowserslist } from '@rsbuild/shared';
|
|
2
3
|
export declare const RUNTIME_CHUNK_NAME = "builder-runtime";
|
|
4
|
+
export declare const JS_REGEX: RegExp;
|
|
3
5
|
export declare const TS_REGEX: RegExp;
|
|
6
|
+
export declare const SCRIPT_REGEX: RegExp;
|
|
7
|
+
export declare const NODE_MODULES_REGEX: RegExp;
|
|
4
8
|
export declare function isServerTarget(target: RsbuildTarget[]): boolean;
|
|
9
|
+
export declare const castArray: <T>(arr?: T | T[] | undefined) => T[];
|
|
10
|
+
export declare function applyScriptCondition({ rule, chain, config, context, includes, excludes, }: {
|
|
11
|
+
rule: RspackChain.Rule;
|
|
12
|
+
chain: RspackChain;
|
|
13
|
+
config: NormalizedConfig;
|
|
14
|
+
context: RsbuildContext;
|
|
15
|
+
includes: (string | RegExp)[];
|
|
16
|
+
excludes: (string | RegExp)[];
|
|
17
|
+
}): void;
|
|
18
|
+
export declare const isHtmlDisabled: (config: NormalizedConfig, target: RsbuildTarget) => boolean;
|
|
5
19
|
export declare const getHash: (config: NormalizedConfig) => string;
|
|
20
|
+
export declare function getBrowserslistWithDefault(path: string, config: {
|
|
21
|
+
output?: {
|
|
22
|
+
overrideBrowserslist?: OverrideBrowserslist;
|
|
23
|
+
};
|
|
24
|
+
}, target: RsbuildTarget): Promise<string[]>;
|
package/dist/shared/utils.js
CHANGED
|
@@ -18,14 +18,25 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var utils_exports = {};
|
|
20
20
|
__export(utils_exports, {
|
|
21
|
+
JS_REGEX: () => JS_REGEX,
|
|
22
|
+
NODE_MODULES_REGEX: () => NODE_MODULES_REGEX,
|
|
21
23
|
RUNTIME_CHUNK_NAME: () => RUNTIME_CHUNK_NAME,
|
|
24
|
+
SCRIPT_REGEX: () => SCRIPT_REGEX,
|
|
22
25
|
TS_REGEX: () => TS_REGEX,
|
|
26
|
+
applyScriptCondition: () => applyScriptCondition,
|
|
27
|
+
castArray: () => castArray,
|
|
28
|
+
getBrowserslistWithDefault: () => getBrowserslistWithDefault,
|
|
23
29
|
getHash: () => getHash,
|
|
30
|
+
isHtmlDisabled: () => isHtmlDisabled,
|
|
24
31
|
isServerTarget: () => isServerTarget
|
|
25
32
|
});
|
|
26
33
|
module.exports = __toCommonJS(utils_exports);
|
|
34
|
+
var import_shared = require("@rsbuild/shared");
|
|
27
35
|
const RUNTIME_CHUNK_NAME = "builder-runtime";
|
|
36
|
+
const JS_REGEX = /\.(?:js|mjs|cjs|jsx)$/;
|
|
28
37
|
const TS_REGEX = /\.(?:ts|mts|cts|tsx)$/;
|
|
38
|
+
const SCRIPT_REGEX = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/;
|
|
39
|
+
const NODE_MODULES_REGEX = /[\\/]node_modules[\\/]/;
|
|
29
40
|
function isServerTarget(target) {
|
|
30
41
|
return (Array.isArray(target) ? target : [
|
|
31
42
|
target
|
|
@@ -34,6 +45,51 @@ function isServerTarget(target) {
|
|
|
34
45
|
"service-worker"
|
|
35
46
|
].includes(item));
|
|
36
47
|
}
|
|
48
|
+
const castArray = (arr) => {
|
|
49
|
+
if (arr === void 0) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
return Array.isArray(arr) ? arr : [
|
|
53
|
+
arr
|
|
54
|
+
];
|
|
55
|
+
};
|
|
56
|
+
function applyScriptCondition({ rule, chain, config, context, includes, excludes }) {
|
|
57
|
+
rule.include.add({
|
|
58
|
+
and: [
|
|
59
|
+
context.rootPath,
|
|
60
|
+
{
|
|
61
|
+
not: NODE_MODULES_REGEX
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
});
|
|
65
|
+
rule.include.add(/\.(?:ts|tsx|jsx|mts|cts)$/);
|
|
66
|
+
const target = castArray(chain.get("target"));
|
|
67
|
+
const legacyTarget = [
|
|
68
|
+
"es5",
|
|
69
|
+
"es6",
|
|
70
|
+
"es2015",
|
|
71
|
+
"es2016"
|
|
72
|
+
];
|
|
73
|
+
if (legacyTarget.some((item) => target.includes(item))) {
|
|
74
|
+
rule.include.add(/[\\/]@rsbuild[\\/]core[\\/]dist[\\/]/);
|
|
75
|
+
}
|
|
76
|
+
for (const condition of [
|
|
77
|
+
...includes,
|
|
78
|
+
...config.source.include || []
|
|
79
|
+
]) {
|
|
80
|
+
rule.include.add(condition);
|
|
81
|
+
}
|
|
82
|
+
for (const condition of [
|
|
83
|
+
...excludes,
|
|
84
|
+
...config.source.exclude || []
|
|
85
|
+
]) {
|
|
86
|
+
rule.exclude.add(condition);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const isHtmlDisabled = (config, target) => {
|
|
90
|
+
const { htmlPlugin } = config.tools;
|
|
91
|
+
return htmlPlugin === false || Array.isArray(htmlPlugin) && htmlPlugin.includes(false) || target !== "web";
|
|
92
|
+
};
|
|
37
93
|
const getHash = (config) => {
|
|
38
94
|
const { filenameHash } = config.output;
|
|
39
95
|
if (typeof filenameHash === "string") {
|
|
@@ -41,10 +97,49 @@ const getHash = (config) => {
|
|
|
41
97
|
}
|
|
42
98
|
return filenameHash ? ".[contenthash:8]" : "";
|
|
43
99
|
};
|
|
100
|
+
const DEFAULT_WEB_BROWSERSLIST = [
|
|
101
|
+
"> 0.01%",
|
|
102
|
+
"not dead",
|
|
103
|
+
"not op_mini all"
|
|
104
|
+
];
|
|
105
|
+
const DEFAULT_BROWSERSLIST = {
|
|
106
|
+
web: DEFAULT_WEB_BROWSERSLIST,
|
|
107
|
+
node: [
|
|
108
|
+
"node >= 14"
|
|
109
|
+
],
|
|
110
|
+
"web-worker": DEFAULT_WEB_BROWSERSLIST,
|
|
111
|
+
"service-worker": DEFAULT_WEB_BROWSERSLIST
|
|
112
|
+
};
|
|
113
|
+
async function getBrowserslistWithDefault(path, config, target) {
|
|
114
|
+
const { overrideBrowserslist: overrides = {} } = (config === null || config === void 0 ? void 0 : config.output) || {};
|
|
115
|
+
if (target === "web" || target === "web-worker") {
|
|
116
|
+
if (Array.isArray(overrides)) {
|
|
117
|
+
return overrides;
|
|
118
|
+
}
|
|
119
|
+
if (overrides[target]) {
|
|
120
|
+
return overrides[target];
|
|
121
|
+
}
|
|
122
|
+
const browserslistrc = await (0, import_shared.getBrowserslist)(path);
|
|
123
|
+
if (browserslistrc) {
|
|
124
|
+
return browserslistrc;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (!Array.isArray(overrides) && overrides[target]) {
|
|
128
|
+
return overrides[target];
|
|
129
|
+
}
|
|
130
|
+
return DEFAULT_BROWSERSLIST[target];
|
|
131
|
+
}
|
|
44
132
|
// Annotate the CommonJS export names for ESM import in node:
|
|
45
133
|
0 && (module.exports = {
|
|
134
|
+
JS_REGEX,
|
|
135
|
+
NODE_MODULES_REGEX,
|
|
46
136
|
RUNTIME_CHUNK_NAME,
|
|
137
|
+
SCRIPT_REGEX,
|
|
47
138
|
TS_REGEX,
|
|
139
|
+
applyScriptCondition,
|
|
140
|
+
castArray,
|
|
141
|
+
getBrowserslistWithDefault,
|
|
48
142
|
getHash,
|
|
143
|
+
isHtmlDisabled,
|
|
49
144
|
isServerTarget
|
|
50
145
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { NodeEnv,
|
|
2
|
-
import type { DevConfig, RsbuildConfig, RsbuildTarget, Polyfill, ScriptInject,
|
|
1
|
+
import type { NodeEnv, RequestHandler, HtmlTagDescriptor } from '@rsbuild/shared';
|
|
2
|
+
import type { ConfigChainWithContext, ConfigChain, DevConfig, RsbuildConfig, RsbuildTarget, Polyfill, ScriptInject, ServerConfig, RsbuildPluginAPI, SourceConfig, OutputConfig, Rspack } from '@rsbuild/core';
|
|
3
3
|
import type { PluginAssetsRetryOptions } from '@rsbuild/plugin-assets-retry';
|
|
4
4
|
import type { PluginStyledComponentsOptions } from '@rsbuild/plugin-styled-components';
|
|
5
5
|
import type { PluginRemOptions } from '@rsbuild/plugin-rem';
|
|
@@ -17,15 +17,35 @@ import type { StartDevServerOptions, UniBuilderStartServerResult } from './share
|
|
|
17
17
|
import type { PluginSourceBuildOptions } from '@rsbuild/plugin-source-build';
|
|
18
18
|
import type TerserPlugin from 'terser-webpack-plugin';
|
|
19
19
|
type ArrayOrNot<T> = T | T[];
|
|
20
|
+
export type Stats = Omit<Rspack.Stats, '#private' | 'hash'>;
|
|
21
|
+
export type RspackConfig = Rspack.Configuration;
|
|
22
|
+
export type MultiStats = Omit<Rspack.MultiStats, '#private' | 'hash' | 'stats'> & {
|
|
23
|
+
stats: Stats[];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* custom properties
|
|
27
|
+
* e.g. { name: 'viewport' content: 'width=500, initial-scale=1' }
|
|
28
|
+
* */
|
|
29
|
+
type MetaAttrs = {
|
|
30
|
+
[attrName: string]: string | boolean;
|
|
31
|
+
};
|
|
32
|
+
export type MetaOptions = {
|
|
33
|
+
/**
|
|
34
|
+
* name content pair
|
|
35
|
+
* e.g. { viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no' }`
|
|
36
|
+
* */
|
|
37
|
+
[name: string]: string | false | MetaAttrs;
|
|
38
|
+
};
|
|
20
39
|
export type CreateBuilderCommonOptions = {
|
|
21
|
-
entry?:
|
|
40
|
+
entry?: SourceConfig['entry'];
|
|
22
41
|
frameworkConfigPath?: string;
|
|
23
42
|
target?: RsbuildTarget | RsbuildTarget[];
|
|
24
43
|
/** The root path of current project. */
|
|
25
44
|
cwd: string;
|
|
26
45
|
};
|
|
46
|
+
export type BundlerType = 'rspack' | 'webpack';
|
|
27
47
|
export type CreateUniBuilderOptions = {
|
|
28
|
-
bundlerType:
|
|
48
|
+
bundlerType: BundlerType;
|
|
29
49
|
config: UniBuilderConfig;
|
|
30
50
|
} & Partial<CreateBuilderCommonOptions>;
|
|
31
51
|
export type GlobalVars = Record<string, any>;
|
|
@@ -193,11 +213,11 @@ export type UniBuilderExtraConfig = {
|
|
|
193
213
|
/**
|
|
194
214
|
* @deprecated use `output.inlineScripts` instead
|
|
195
215
|
*/
|
|
196
|
-
enableInlineScripts?:
|
|
216
|
+
enableInlineScripts?: OutputConfig['inlineScripts'];
|
|
197
217
|
/**
|
|
198
218
|
* @deprecated use `output.inlineStyles` instead
|
|
199
219
|
*/
|
|
200
|
-
enableInlineStyles?:
|
|
220
|
+
enableInlineStyles?: OutputConfig['injectStyles'];
|
|
201
221
|
/**
|
|
202
222
|
* Configure the default export type of SVG files.
|
|
203
223
|
*/
|
|
@@ -320,14 +340,14 @@ export type UniBuilderPluginAPI = {
|
|
|
320
340
|
getBuilderConfig: () => Readonly<any>;
|
|
321
341
|
modifyBuilderConfig: (fn: (config: any, utils: {
|
|
322
342
|
mergeBuilderConfig: <T>(...configs: T[]) => T;
|
|
323
|
-
}) =>
|
|
343
|
+
}) => any | Promise<any>) => void;
|
|
324
344
|
};
|
|
325
345
|
/**
|
|
326
346
|
* compat legacy modern.js builder plugin
|
|
327
347
|
*/
|
|
328
348
|
export type UniBuilderPlugin = {
|
|
329
349
|
name: string;
|
|
330
|
-
setup: (api: UniBuilderPluginAPI) =>
|
|
350
|
+
setup: (api: UniBuilderPluginAPI) => void | Promise<void>;
|
|
331
351
|
pre?: string[];
|
|
332
352
|
post?: string[];
|
|
333
353
|
remove?: 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,6 +17,14 @@ 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 ModuleScopePlugin_exports = {};
|
|
20
30
|
__export(ModuleScopePlugin_exports, {
|
|
@@ -22,7 +32,7 @@ __export(ModuleScopePlugin_exports, {
|
|
|
22
32
|
});
|
|
23
33
|
module.exports = __toCommonJS(ModuleScopePlugin_exports);
|
|
24
34
|
var import_path = require("path");
|
|
25
|
-
var
|
|
35
|
+
var import_picocolors = __toESM(require("picocolors"));
|
|
26
36
|
var import_utils = require("@modern-js/utils");
|
|
27
37
|
class ModuleScopePlugin {
|
|
28
38
|
apply(resolver) {
|
|
@@ -56,12 +66,12 @@ class ModuleScopePlugin {
|
|
|
56
66
|
const requestRelative = (0, import_path.relative)(allowedDir, requestFullPath);
|
|
57
67
|
return requestRelative.startsWith("../") || requestRelative.startsWith("..\\");
|
|
58
68
|
})) {
|
|
59
|
-
let message = `You attempted to import ${
|
|
69
|
+
let message = `You attempted to import ${import_picocolors.default.bold(request.__innerRequest_request)} which is not allowed. `;
|
|
60
70
|
if (allowedDirs.length) {
|
|
61
|
-
message += `Allowed dirs: ${
|
|
71
|
+
message += `Allowed dirs: ${import_picocolors.default.bold(relativeAllowedDirs.join(","))}. `;
|
|
62
72
|
}
|
|
63
73
|
if (allowedPatterns.length) {
|
|
64
|
-
message += `Allowed patterns: ${
|
|
74
|
+
message += `Allowed patterns: ${import_picocolors.default.bold(allowedPatterns.map((p) => p.toString()).join(","))}. `;
|
|
65
75
|
}
|
|
66
76
|
message += `Please check the source.moduleScopes configuration.`;
|
|
67
77
|
const scopeError = new Error(message);
|
|
@@ -36,8 +36,8 @@ var import_cloneDeep = __toESM(require("lodash/cloneDeep"));
|
|
|
36
36
|
var import_web = require("@rsbuild/babel-preset/web");
|
|
37
37
|
var import_node = require("@rsbuild/babel-preset/node");
|
|
38
38
|
var import_utils = require("@modern-js/utils");
|
|
39
|
-
var import_shared = require("@rsbuild/shared");
|
|
40
39
|
var import_plugin_babel = require("@rsbuild/plugin-babel");
|
|
40
|
+
var import_utils2 = require("../../shared/utils");
|
|
41
41
|
const getPresetReact = (rootPath, isProd) => {
|
|
42
42
|
const isNewJsx = (0, import_utils.isBeyondReact17)(rootPath);
|
|
43
43
|
const presetReactOptions = {
|
|
@@ -65,7 +65,7 @@ const pluginBabel = (options, extraOptions) => ({
|
|
|
65
65
|
order: "pre",
|
|
66
66
|
handler: async (chain, { CHAIN_ID, target, isProd, isServer, isServiceWorker }) => {
|
|
67
67
|
const config = api.getNormalizedConfig();
|
|
68
|
-
const browserslist = await (0,
|
|
68
|
+
const browserslist = await (0, import_utils2.getBrowserslistWithDefault)(api.context.rootPath, config, target);
|
|
69
69
|
const getBabelOptions = (config2) => {
|
|
70
70
|
var _baseBabelConfig_presets;
|
|
71
71
|
const includes2 = [];
|
|
@@ -138,7 +138,7 @@ const pluginBabel = (options, extraOptions) => ({
|
|
|
138
138
|
};
|
|
139
139
|
const { babelOptions, includes, excludes } = getBabelOptions(config);
|
|
140
140
|
const rule = chain.module.rule(CHAIN_ID.RULE.JS);
|
|
141
|
-
(0,
|
|
141
|
+
(0, import_utils2.applyScriptCondition)({
|
|
142
142
|
chain,
|
|
143
143
|
rule,
|
|
144
144
|
config,
|
|
@@ -146,7 +146,7 @@ const pluginBabel = (options, extraOptions) => ({
|
|
|
146
146
|
includes,
|
|
147
147
|
excludes
|
|
148
148
|
});
|
|
149
|
-
rule.test(
|
|
149
|
+
rule.test(import_utils2.SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(require.resolve("babel-loader")).options(babelOptions);
|
|
150
150
|
chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).mimetype({
|
|
151
151
|
or: [
|
|
152
152
|
"text/javascript",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
import type { DevConfig } from '@rsbuild/shared';
|
|
1
|
+
import type { RsbuildPlugin, DevConfig } from '@rsbuild/core';
|
|
3
2
|
type LazyCompilationOptions = DevConfig['lazyCompilation'];
|
|
4
3
|
export declare const pluginLazyCompilation: (options: LazyCompilationOptions) => RsbuildPlugin;
|
|
5
4
|
export {};
|
|
@@ -31,7 +31,6 @@ __export(minimize_exports, {
|
|
|
31
31
|
pluginMinimize: () => pluginMinimize
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(minimize_exports);
|
|
34
|
-
var import_shared = require("@rsbuild/shared");
|
|
35
34
|
var import_utils = require("@modern-js/utils");
|
|
36
35
|
function applyRemoveConsole(options, config) {
|
|
37
36
|
const { removeConsole } = config.performance;
|
|
@@ -50,7 +49,7 @@ function applyRemoveConsole(options, config) {
|
|
|
50
49
|
}
|
|
51
50
|
return options;
|
|
52
51
|
}
|
|
53
|
-
async function applyJSMinimizer(chain, config, userTerserConfig) {
|
|
52
|
+
async function applyJSMinimizer(chain, config, CHAIN_ID, userTerserConfig) {
|
|
54
53
|
const { default: TerserPlugin } = await Promise.resolve().then(() => __toESM(require("terser-webpack-plugin")));
|
|
55
54
|
const DEFAULT_OPTIONS = {
|
|
56
55
|
terserOptions: {
|
|
@@ -78,7 +77,7 @@ async function applyJSMinimizer(chain, config, userTerserConfig) {
|
|
|
78
77
|
break;
|
|
79
78
|
}
|
|
80
79
|
const mergedOptions = (0, import_utils.applyOptionsChain)(DEFAULT_OPTIONS, userTerserConfig);
|
|
81
|
-
chain.optimization.minimizer(
|
|
80
|
+
chain.optimization.minimizer(CHAIN_ID.MINIMIZER.JS).use(TerserPlugin, [
|
|
82
81
|
// Due to terser-webpack-plugin has changed the type of class, which using a generic type in
|
|
83
82
|
// constructor, leading auto inference of parameters of plugin constructor is not possible, using any instead
|
|
84
83
|
mergedOptions
|
|
@@ -87,14 +86,14 @@ async function applyJSMinimizer(chain, config, userTerserConfig) {
|
|
|
87
86
|
const pluginMinimize = (userTerserConfig) => ({
|
|
88
87
|
name: "uni-builder:minimize",
|
|
89
88
|
setup(api) {
|
|
90
|
-
api.modifyBundlerChain(async (chain, { isProd }) => {
|
|
89
|
+
api.modifyBundlerChain(async (chain, { isProd, CHAIN_ID }) => {
|
|
91
90
|
const config = api.getNormalizedConfig();
|
|
92
91
|
const { minify } = config.output;
|
|
93
92
|
if (minify === false || !isProd) {
|
|
94
93
|
return;
|
|
95
94
|
}
|
|
96
95
|
if (minify === true || (minify === null || minify === void 0 ? void 0 : minify.js) !== false) {
|
|
97
|
-
await applyJSMinimizer(chain, config, userTerserConfig);
|
|
96
|
+
await applyJSMinimizer(chain, config, CHAIN_ID, userTerserConfig);
|
|
98
97
|
}
|
|
99
98
|
});
|
|
100
99
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
import { type ConfigChain } from '@rsbuild/shared';
|
|
1
|
+
import type { RsbuildPlugin, ConfigChain } from '@rsbuild/core';
|
|
3
2
|
import type { ModuleScopes } from '../../types';
|
|
4
3
|
export declare const isPrimitiveScope: (items: unknown[]) => items is (string | RegExp)[];
|
|
5
4
|
export declare const applyScopeChain: (defaults: ModuleScopes, options: ConfigChain<ModuleScopes>) => ModuleScopes;
|
|
@@ -31,7 +31,6 @@ __export(react_exports, {
|
|
|
31
31
|
pluginReact: () => pluginReact
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(react_exports);
|
|
34
|
-
var import_shared = require("@rsbuild/shared");
|
|
35
34
|
const pluginReact = () => ({
|
|
36
35
|
name: "uni-builder:react",
|
|
37
36
|
pre: [
|
|
@@ -40,7 +39,8 @@ const pluginReact = () => ({
|
|
|
40
39
|
setup(api) {
|
|
41
40
|
api.modifyBundlerChain(async (chain, utils) => {
|
|
42
41
|
const config = api.getNormalizedConfig();
|
|
43
|
-
|
|
42
|
+
const usingHMR = !utils.isProd && config.dev.hmr && utils.target === "web";
|
|
43
|
+
if (!usingHMR) {
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
const { CHAIN_ID } = utils;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
import { type ConfigChain } from '@rsbuild/shared';
|
|
1
|
+
import type { RsbuildPlugin, ConfigChain } from '@rsbuild/core';
|
|
3
2
|
import type { PluginStyledComponentsOptions } from '@rsbuild/plugin-styled-components';
|
|
4
3
|
export declare const pluginStyledComponents: (userConfig?: ConfigChain<PluginStyledComponentsOptions>) => RsbuildPlugin;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ConfigChainWithContext } from '@rsbuild/core';
|
|
2
2
|
import { PluginBabelOptions } from '@rsbuild/plugin-babel';
|
|
3
3
|
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
4
4
|
import type { Options as RawTSLoaderOptions } from 'ts-loader';
|
|
5
|
+
type OneOrMany<T> = T | T[];
|
|
6
|
+
type FileFilterUtil = (items: OneOrMany<string | RegExp>) => void;
|
|
5
7
|
export type TSLoaderOptions = Partial<RawTSLoaderOptions>;
|
|
6
8
|
export type PluginTsLoaderOptions = ConfigChainWithContext<TSLoaderOptions, {
|
|
7
9
|
/**
|
|
@@ -16,3 +18,4 @@ export type PluginTsLoaderOptions = ConfigChainWithContext<TSLoaderOptions, {
|
|
|
16
18
|
addExcludes: FileFilterUtil;
|
|
17
19
|
}>;
|
|
18
20
|
export declare const pluginTsLoader: (options?: PluginTsLoaderOptions, babelOptions?: PluginBabelOptions['babelLoaderOptions']) => RsbuildPlugin;
|
|
21
|
+
export {};
|
|
@@ -31,7 +31,6 @@ __export(tsLoader_exports, {
|
|
|
31
31
|
pluginTsLoader: () => pluginTsLoader
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(tsLoader_exports);
|
|
34
|
-
var import_shared = require("@rsbuild/shared");
|
|
35
34
|
var import_utils = require("@modern-js/utils");
|
|
36
35
|
var import_plugin_babel = require("@rsbuild/plugin-babel");
|
|
37
36
|
var import_web = require("@rsbuild/babel-preset/web");
|
|
@@ -50,7 +49,7 @@ const pluginTsLoader = (options, babelOptions) => {
|
|
|
50
49
|
var _baseBabelConfig_presets;
|
|
51
50
|
const config = api.getNormalizedConfig();
|
|
52
51
|
const { rootPath } = api.context;
|
|
53
|
-
const browserslist = await (0,
|
|
52
|
+
const browserslist = await (0, import_utils2.getBrowserslistWithDefault)(rootPath, config, target);
|
|
54
53
|
const baseBabelConfig = (0, import_web.getBabelConfigForWeb)({
|
|
55
54
|
presetEnv: {
|
|
56
55
|
targets: browserslist,
|
|
@@ -64,10 +63,10 @@ const pluginTsLoader = (options, babelOptions) => {
|
|
|
64
63
|
const excludes = [];
|
|
65
64
|
const tsLoaderUtils = {
|
|
66
65
|
addIncludes(items) {
|
|
67
|
-
includes.push(...(0,
|
|
66
|
+
includes.push(...(0, import_utils2.castArray)(items));
|
|
68
67
|
},
|
|
69
68
|
addExcludes(items) {
|
|
70
|
-
excludes.push(...(0,
|
|
69
|
+
excludes.push(...(0, import_utils2.castArray)(items));
|
|
71
70
|
}
|
|
72
71
|
};
|
|
73
72
|
const tsLoaderDefaultOptions = {
|
|
@@ -85,7 +84,7 @@ const pluginTsLoader = (options, babelOptions) => {
|
|
|
85
84
|
tsLoaderUtils
|
|
86
85
|
);
|
|
87
86
|
const rule = chain.module.rule(CHAIN_ID.RULE.TS);
|
|
88
|
-
(0,
|
|
87
|
+
(0, import_utils2.applyScriptCondition)({
|
|
89
88
|
chain,
|
|
90
89
|
rule,
|
|
91
90
|
config,
|
|
@@ -93,7 +92,7 @@ const pluginTsLoader = (options, babelOptions) => {
|
|
|
93
92
|
includes,
|
|
94
93
|
excludes
|
|
95
94
|
});
|
|
96
|
-
chain.module.rule(CHAIN_ID.RULE.JS).test(
|
|
95
|
+
chain.module.rule(CHAIN_ID.RULE.JS).test(import_utils2.JS_REGEX);
|
|
97
96
|
rule.test(import_utils2.TS_REGEX).use(CHAIN_ID.USE.BABEL).loader(require.resolve("babel-loader")).options({
|
|
98
97
|
...babelLoaderOptions,
|
|
99
98
|
// fix repeatedly insert babel plugin in some boundary cases
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/uni-builder",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.55.0",
|
|
4
4
|
"description": "Unified builder for Modern.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"babel-plugin-import": "1.13.5",
|
|
52
52
|
"babel-plugin-styled-components": "1.13.3",
|
|
53
53
|
"babel-plugin-transform-react-remove-prop-types": "0.4.24",
|
|
54
|
+
"browserslist": "4.23.1",
|
|
54
55
|
"cssnano": "6.0.1",
|
|
55
56
|
"glob": "^9.3.5",
|
|
56
57
|
"html-webpack-plugin": "5.5.3",
|
|
@@ -63,15 +64,17 @@
|
|
|
63
64
|
"postcss-media-minmax": "5.0.0",
|
|
64
65
|
"postcss-nesting": "12.0.1",
|
|
65
66
|
"postcss-page-break": "3.0.4",
|
|
67
|
+
"picocolors": "^1.0.1",
|
|
66
68
|
"react-refresh": "^0.14.0",
|
|
67
69
|
"rspack-manifest-plugin": "5.0.0",
|
|
68
70
|
"terser-webpack-plugin": "5.3.10",
|
|
71
|
+
"ts-deepmerge": "7.0.0",
|
|
69
72
|
"ts-loader": "9.4.4",
|
|
70
73
|
"webpack": "^5.92.0",
|
|
71
74
|
"webpack-subresource-integrity": "5.1.0",
|
|
72
|
-
"@modern-js/utils": "2.
|
|
73
|
-
"@modern-js/server": "2.
|
|
74
|
-
"@modern-js/prod-server": "2.
|
|
75
|
+
"@modern-js/utils": "2.55.0",
|
|
76
|
+
"@modern-js/server": "2.55.0",
|
|
77
|
+
"@modern-js/prod-server": "2.55.0"
|
|
75
78
|
},
|
|
76
79
|
"devDependencies": {
|
|
77
80
|
"@rsbuild/plugin-swc": "0.7.10",
|
|
@@ -79,8 +82,8 @@
|
|
|
79
82
|
"react": "^18.2.0",
|
|
80
83
|
"react-dom": "^18.2.0",
|
|
81
84
|
"typescript": "^5.3.0",
|
|
82
|
-
"@scripts/
|
|
83
|
-
"@scripts/
|
|
85
|
+
"@scripts/vitest-config": "2.55.0",
|
|
86
|
+
"@scripts/build": "2.55.0"
|
|
84
87
|
},
|
|
85
88
|
"publishConfig": {
|
|
86
89
|
"access": "public",
|