@modern-js/uni-builder 2.54.6 → 2.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -6
- package/dist/index.d.ts +3 -4
- package/dist/index.js +6 -0
- package/dist/rspack/index.js +7 -2
- package/dist/rspack/plugins/babel-post.d.ts +1 -1
- package/dist/rspack/plugins/babel-post.js +2 -2
- package/dist/shared/compatLegacyPlugin.js +3 -2
- package/dist/shared/devServer.d.ts +4 -3
- package/dist/shared/devServer.js +18 -8
- package/dist/shared/getCssSupport.js +1 -1
- package/dist/shared/manifest.d.ts +1 -1
- package/dist/shared/parseCommonConfig.js +34 -70
- package/dist/shared/plugins/antd.d.ts +1 -1
- package/dist/shared/plugins/antd.js +3 -8
- package/dist/shared/plugins/arco.d.ts +1 -1
- package/dist/shared/plugins/arco.js +6 -8
- package/dist/shared/plugins/devtools.d.ts +1 -1
- package/dist/shared/plugins/emitRouteFile.d.ts +1 -1
- package/dist/shared/plugins/emitRouteFile.js +13 -8
- package/dist/shared/plugins/environmentDefaults.d.ts +3 -0
- package/dist/shared/plugins/environmentDefaults.js +81 -0
- 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/htmlMinify.d.ts +2 -0
- package/dist/shared/plugins/htmlMinify.js +140 -0
- package/dist/shared/plugins/mainFields.d.ts +1 -2
- package/dist/shared/plugins/postcssLegacy.d.ts +1 -1
- package/dist/shared/plugins/postcssLegacy.js +9 -6
- package/dist/shared/plugins/runtimeChunk.js +2 -2
- package/dist/shared/plugins/splitChunk.js +22 -4
- package/dist/shared/utils.d.ts +23 -3
- package/dist/shared/utils.js +131 -9
- package/dist/types.d.ts +44 -12
- package/dist/webpack/ModuleScopePlugin.js +14 -4
- package/dist/webpack/index.js +7 -2
- package/dist/webpack/plugins/babel.d.ts +1 -1
- package/dist/webpack/plugins/babel.js +15 -17
- package/dist/webpack/plugins/lazyCompilation.d.ts +1 -2
- package/dist/webpack/plugins/minimize.d.ts +1 -1
- package/dist/webpack/plugins/minimize.js +5 -6
- package/dist/webpack/plugins/moduleScopes.d.ts +1 -2
- package/dist/webpack/plugins/react.js +3 -3
- package/dist/webpack/plugins/styledComponents.d.ts +1 -2
- package/dist/webpack/plugins/styledComponents.js +2 -2
- package/dist/webpack/plugins/tsLoader.d.ts +5 -2
- package/dist/webpack/plugins/tsLoader.js +9 -10
- package/package.json +36 -31
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { DevConfig, RsbuildConfig, RsbuildTarget, Polyfill, ScriptInject, RsbuildEntry, ServerConfig, RsbuildPluginAPI } from '@rsbuild/core';
|
|
1
|
+
import type { ConfigChainWithContext, ConfigChain, DevConfig, RsbuildConfig, RsbuildTarget, Polyfill, ScriptInject, ServerConfig, RsbuildPluginAPI, OutputConfig, DistPathConfig, Rspack, RequestHandler, NodeEnv, HtmlTagDescriptor } from '@rsbuild/core';
|
|
3
2
|
import type { PluginAssetsRetryOptions } from '@rsbuild/plugin-assets-retry';
|
|
4
3
|
import type { PluginStyledComponentsOptions } from '@rsbuild/plugin-styled-components';
|
|
5
4
|
import type { PluginRemOptions } from '@rsbuild/plugin-rem';
|
|
@@ -16,16 +15,35 @@ import type { AliasOption } from '@modern-js/utils';
|
|
|
16
15
|
import type { StartDevServerOptions, UniBuilderStartServerResult } from './shared/devServer';
|
|
17
16
|
import type { PluginSourceBuildOptions } from '@rsbuild/plugin-source-build';
|
|
18
17
|
import type TerserPlugin from 'terser-webpack-plugin';
|
|
18
|
+
import type { Options as HTMLPluginOptions } from 'html-webpack-plugin';
|
|
19
19
|
type ArrayOrNot<T> = T | T[];
|
|
20
|
+
export type Stats = Omit<Rspack.Stats, '#private' | 'hash' | 'startTime' | 'endTime'>;
|
|
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?: RsbuildEntry;
|
|
22
40
|
frameworkConfigPath?: string;
|
|
23
|
-
target?: RsbuildTarget | RsbuildTarget[];
|
|
24
41
|
/** The root path of current project. */
|
|
25
42
|
cwd: string;
|
|
26
43
|
};
|
|
44
|
+
export type BundlerType = 'rspack' | 'webpack';
|
|
27
45
|
export type CreateUniBuilderOptions = {
|
|
28
|
-
bundlerType:
|
|
46
|
+
bundlerType: BundlerType;
|
|
29
47
|
config: UniBuilderConfig;
|
|
30
48
|
} & Partial<CreateBuilderCommonOptions>;
|
|
31
49
|
export type GlobalVars = Record<string, any>;
|
|
@@ -63,6 +81,10 @@ export type TerserPluginOptions = TerserPlugin.BasePluginOptions & TerserPlugin.
|
|
|
63
81
|
export type ToolsTerserConfig = ConfigChain<TerserPluginOptions>;
|
|
64
82
|
export type UniBuilderExtraConfig = {
|
|
65
83
|
tools?: {
|
|
84
|
+
htmlPlugin?: boolean | ConfigChainWithContext<HTMLPluginOptions, {
|
|
85
|
+
entryName: string;
|
|
86
|
+
entryValue: (string | string[] | Rspack.EntryDescription)[];
|
|
87
|
+
}>;
|
|
66
88
|
styledComponents?: false | PluginStyledComponentsOptions;
|
|
67
89
|
devServer?: ToolsDevServerConfig;
|
|
68
90
|
/**
|
|
@@ -106,6 +128,10 @@ export type UniBuilderExtraConfig = {
|
|
|
106
128
|
sass?: PluginSassOptions['sassLoaderOptions'];
|
|
107
129
|
};
|
|
108
130
|
dev?: {
|
|
131
|
+
/** Set the page URL to open when the server starts. */
|
|
132
|
+
startUrl?: boolean | string | string[];
|
|
133
|
+
/** Execute a callback function before opening the `startUrl`. */
|
|
134
|
+
beforeStartUrl?: () => Promise<void> | void;
|
|
109
135
|
/**
|
|
110
136
|
* Used to set the host of Dev Server.
|
|
111
137
|
*/
|
|
@@ -193,11 +219,11 @@ export type UniBuilderExtraConfig = {
|
|
|
193
219
|
/**
|
|
194
220
|
* @deprecated use `output.inlineScripts` instead
|
|
195
221
|
*/
|
|
196
|
-
enableInlineScripts?:
|
|
222
|
+
enableInlineScripts?: OutputConfig['inlineScripts'];
|
|
197
223
|
/**
|
|
198
224
|
* @deprecated use `output.inlineStyles` instead
|
|
199
225
|
*/
|
|
200
|
-
enableInlineStyles?:
|
|
226
|
+
enableInlineStyles?: OutputConfig['injectStyles'];
|
|
201
227
|
/**
|
|
202
228
|
* Configure the default export type of SVG files.
|
|
203
229
|
*/
|
|
@@ -298,7 +324,7 @@ export type OverridesUniBuilderInstance = {
|
|
|
298
324
|
startDevServer: (options: StartDevServerOptions) => Promise<UniBuilderStartServerResult>;
|
|
299
325
|
};
|
|
300
326
|
export type UniBuilderContext = RsbuildPluginAPI['context'] & {
|
|
301
|
-
target:
|
|
327
|
+
target: RsbuildTarget[];
|
|
302
328
|
framework: string;
|
|
303
329
|
srcPath: string;
|
|
304
330
|
entry: Record<string, string | string[]>;
|
|
@@ -320,28 +346,34 @@ export type UniBuilderPluginAPI = {
|
|
|
320
346
|
getBuilderConfig: () => Readonly<any>;
|
|
321
347
|
modifyBuilderConfig: (fn: (config: any, utils: {
|
|
322
348
|
mergeBuilderConfig: <T>(...configs: T[]) => T;
|
|
323
|
-
}) =>
|
|
349
|
+
}) => any | Promise<any>) => void;
|
|
324
350
|
};
|
|
325
351
|
/**
|
|
326
352
|
* compat legacy modern.js builder plugin
|
|
327
353
|
*/
|
|
328
354
|
export type UniBuilderPlugin = {
|
|
329
355
|
name: string;
|
|
330
|
-
setup: (api: UniBuilderPluginAPI) =>
|
|
356
|
+
setup: (api: UniBuilderPluginAPI) => void | Promise<void>;
|
|
331
357
|
pre?: string[];
|
|
332
358
|
post?: string[];
|
|
333
359
|
remove?: string[];
|
|
334
360
|
};
|
|
361
|
+
export type DistPath = DistPathConfig & {
|
|
362
|
+
server?: string;
|
|
363
|
+
worker?: string;
|
|
364
|
+
};
|
|
335
365
|
export type UniBuilderConfig = {
|
|
336
366
|
dev?: RsbuildConfig['dev'];
|
|
337
367
|
html?: RsbuildConfig['html'];
|
|
338
|
-
output?: Omit<NonNullable<RsbuildConfig['output']>, 'polyfill'> & {
|
|
368
|
+
output?: Omit<NonNullable<RsbuildConfig['output']>, 'polyfill' | 'distPath'> & {
|
|
339
369
|
polyfill?: Polyfill | 'ua';
|
|
370
|
+
distPath?: DistPath;
|
|
340
371
|
};
|
|
341
372
|
performance?: RsbuildConfig['performance'];
|
|
342
373
|
security?: RsbuildConfig['security'];
|
|
343
|
-
tools?: RsbuildConfig['tools']
|
|
374
|
+
tools?: Omit<NonNullable<RsbuildConfig['tools']>, 'htmlPlugin'>;
|
|
344
375
|
source?: Omit<NonNullable<RsbuildConfig['source']>, 'alias'>;
|
|
345
376
|
plugins?: RsbuildConfig['plugins'];
|
|
377
|
+
environments?: RsbuildConfig['environments'];
|
|
346
378
|
} & UniBuilderExtraConfig;
|
|
347
379
|
export {};
|
|
@@ -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);
|
package/dist/webpack/index.js
CHANGED
|
@@ -38,6 +38,7 @@ var import_compatLegacyPlugin = require("../shared/compatLegacyPlugin");
|
|
|
38
38
|
var import_moduleScopes = require("./plugins/moduleScopes");
|
|
39
39
|
var import_babel = require("./plugins/babel");
|
|
40
40
|
var import_react = require("./plugins/react");
|
|
41
|
+
var import_utils = require("../shared/utils");
|
|
41
42
|
async function parseConfig(uniBuilderConfig, options) {
|
|
42
43
|
var _uniBuilderConfig_tools, _uniBuilderConfig_performance, _uniBuilderConfig_tools1, _uniBuilderConfig_output, _uniBuilderConfig_security, _uniBuilderConfig_experiments, _uniBuilderConfig_tools2;
|
|
43
44
|
const { rsbuildConfig, rsbuildPlugins } = await (0, import_parseCommonConfig.parseCommonConfig)(uniBuilderConfig, options);
|
|
@@ -68,9 +69,13 @@ async function parseConfig(uniBuilderConfig, options) {
|
|
|
68
69
|
rsbuildPlugins.push(pluginLazyCompilation((_uniBuilderConfig_experiments1 = uniBuilderConfig.experiments) === null || _uniBuilderConfig_experiments1 === void 0 ? void 0 : _uniBuilderConfig_experiments1.lazyCompilation));
|
|
69
70
|
}
|
|
70
71
|
if (((_uniBuilderConfig_tools2 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools2 === void 0 ? void 0 : _uniBuilderConfig_tools2.styledComponents) !== false) {
|
|
71
|
-
var _uniBuilderConfig_tools4;
|
|
72
|
+
var _uniBuilderConfig_tools4, _uniBuilderConfig_environments;
|
|
72
73
|
const { pluginStyledComponents } = await Promise.resolve().then(() => __toESM(require("./plugins/styledComponents")));
|
|
73
|
-
|
|
74
|
+
const options2 = ((_uniBuilderConfig_tools4 = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools4 === void 0 ? void 0 : _uniBuilderConfig_tools4.styledComponents) || {};
|
|
75
|
+
if ((_uniBuilderConfig_environments = uniBuilderConfig.environments) === null || _uniBuilderConfig_environments === void 0 ? void 0 : _uniBuilderConfig_environments[import_utils.SERVICE_WORKER_ENVIRONMENT_NAME]) {
|
|
76
|
+
options2.ssr = true;
|
|
77
|
+
}
|
|
78
|
+
rsbuildPlugins.push(pluginStyledComponents(options2));
|
|
74
79
|
}
|
|
75
80
|
return {
|
|
76
81
|
rsbuildConfig,
|
|
@@ -33,11 +33,11 @@ __export(babel_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(babel_exports);
|
|
35
35
|
var import_cloneDeep = __toESM(require("lodash/cloneDeep"));
|
|
36
|
-
var import_web = require("@
|
|
37
|
-
var import_node = require("@
|
|
36
|
+
var import_web = require("@modern-js/babel-preset/web");
|
|
37
|
+
var import_node = require("@modern-js/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 = {
|
|
@@ -63,9 +63,9 @@ const pluginBabel = (options, extraOptions) => ({
|
|
|
63
63
|
setup(api) {
|
|
64
64
|
api.modifyBundlerChain({
|
|
65
65
|
order: "pre",
|
|
66
|
-
handler: async (chain, { CHAIN_ID, target, isProd, isServer,
|
|
67
|
-
const config =
|
|
68
|
-
const browserslist = await (0,
|
|
66
|
+
handler: async (chain, { CHAIN_ID, target, isProd, isServer, environment }) => {
|
|
67
|
+
const { config, name } = environment;
|
|
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 = [];
|
|
@@ -87,7 +87,7 @@ const pluginBabel = (options, extraOptions) => ({
|
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
89
|
const decoratorConfig = config2.source.decorators;
|
|
90
|
-
const baseBabelConfig = isServer ||
|
|
90
|
+
const baseBabelConfig = isServer || name === import_utils2.SERVICE_WORKER_ENVIRONMENT_NAME ? (0, import_node.getBabelConfigForNode)({
|
|
91
91
|
presetEnv: {
|
|
92
92
|
targets: [
|
|
93
93
|
"node >= 14"
|
|
@@ -97,7 +97,7 @@ const pluginBabel = (options, extraOptions) => ({
|
|
|
97
97
|
}) : (0, import_web.getBabelConfigForWeb)({
|
|
98
98
|
presetEnv: {
|
|
99
99
|
targets: browserslist,
|
|
100
|
-
useBuiltIns: (0,
|
|
100
|
+
useBuiltIns: (0, import_utils2.getUseBuiltIns)(config2)
|
|
101
101
|
},
|
|
102
102
|
pluginDecorators: decoratorConfig
|
|
103
103
|
});
|
|
@@ -138,15 +138,13 @@ 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
|
-
(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
});
|
|
149
|
-
rule.test(import_shared.SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(require.resolve("babel-loader")).options(babelOptions);
|
|
141
|
+
for (const condition of includes) {
|
|
142
|
+
rule.include.add(condition);
|
|
143
|
+
}
|
|
144
|
+
for (const condition of excludes) {
|
|
145
|
+
rule.exclude.add(condition);
|
|
146
|
+
}
|
|
147
|
+
rule.test(import_utils2.SCRIPT_REGEX).use(CHAIN_ID.USE.BABEL).loader(require.resolve("babel-loader")).options(babelOptions);
|
|
150
148
|
chain.module.rule(CHAIN_ID.RULE.JS_DATA_URI).mimetype({
|
|
151
149
|
or: [
|
|
152
150
|
"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 }) => {
|
|
91
|
-
const config =
|
|
89
|
+
api.modifyBundlerChain(async (chain, { isProd, CHAIN_ID, environment }) => {
|
|
90
|
+
const { config } = environment;
|
|
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: [
|
|
@@ -39,8 +38,9 @@ const pluginReact = () => ({
|
|
|
39
38
|
],
|
|
40
39
|
setup(api) {
|
|
41
40
|
api.modifyBundlerChain(async (chain, utils) => {
|
|
42
|
-
const config =
|
|
43
|
-
|
|
41
|
+
const { config } = utils.environment;
|
|
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;
|
|
@@ -52,8 +52,8 @@ const pluginStyledComponents = (userConfig = {}) => ({
|
|
|
52
52
|
],
|
|
53
53
|
setup(api) {
|
|
54
54
|
api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd }) => {
|
|
55
|
-
const
|
|
56
|
-
const styledComponentsOptions = (0, import_utils.applyOptionsChain)(getDefaultStyledComponentsConfig(isProd,
|
|
55
|
+
const hasSSR = Object.entries(api.getNormalizedConfig().environments).some(([name, config]) => (0, import_utils2.isServerEnvironment)(config.output.target, name));
|
|
56
|
+
const styledComponentsOptions = (0, import_utils.applyOptionsChain)(getDefaultStyledComponentsConfig(isProd, hasSSR), userConfig);
|
|
57
57
|
if (!styledComponentsOptions) {
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { PluginBabelOptions } from '@rsbuild/plugin-babel';
|
|
1
|
+
import { type ConfigChainWithContext } from '@rsbuild/core';
|
|
2
|
+
import { type 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,10 +31,9 @@ __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
|
-
var import_web = require("@
|
|
36
|
+
var import_web = require("@modern-js/babel-preset/web");
|
|
38
37
|
var import_babel = require("./babel");
|
|
39
38
|
var import_utils2 = require("../../shared/utils");
|
|
40
39
|
const pluginTsLoader = (options, babelOptions) => {
|
|
@@ -46,15 +45,15 @@ const pluginTsLoader = (options, babelOptions) => {
|
|
|
46
45
|
setup(api) {
|
|
47
46
|
api.modifyBundlerChain({
|
|
48
47
|
order: "pre",
|
|
49
|
-
handler: async (chain, { isProd, target, CHAIN_ID }) => {
|
|
48
|
+
handler: async (chain, { isProd, target, CHAIN_ID, environment }) => {
|
|
50
49
|
var _baseBabelConfig_presets;
|
|
51
|
-
const config =
|
|
50
|
+
const { config } = environment;
|
|
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,
|
|
57
|
-
useBuiltIns: (0,
|
|
56
|
+
useBuiltIns: (0, import_utils2.getUseBuiltIns)(config)
|
|
58
57
|
}
|
|
59
58
|
});
|
|
60
59
|
(_baseBabelConfig_presets = baseBabelConfig.presets) === null || _baseBabelConfig_presets === void 0 ? void 0 : _baseBabelConfig_presets.push((0, import_babel.getPresetReact)(api.context.rootPath, isProd));
|
|
@@ -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,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/uni-builder",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.56.0",
|
|
4
4
|
"description": "Unified builder for Modern.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/web-infra-dev/modern.js",
|
|
8
|
-
"directory": "packages/
|
|
8
|
+
"directory": "packages/cli/uni-builder"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"type": "commonjs",
|
|
@@ -22,38 +22,38 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@babel/core": "^7.
|
|
25
|
+
"@babel/core": "^7.24.7",
|
|
26
26
|
"@babel/preset-react": "^7.22.15",
|
|
27
|
-
"@babel/types": "^7.
|
|
27
|
+
"@babel/types": "^7.24.7",
|
|
28
28
|
"@pmmmwh/react-refresh-webpack-plugin": "0.5.10",
|
|
29
|
-
"@rsbuild/
|
|
30
|
-
"@rsbuild/
|
|
31
|
-
"@rsbuild/plugin-
|
|
32
|
-
"@rsbuild/plugin-
|
|
33
|
-
"@rsbuild/plugin-
|
|
34
|
-
"@rsbuild/plugin-
|
|
35
|
-
"@rsbuild/plugin-
|
|
36
|
-
"@rsbuild/plugin-
|
|
37
|
-
"@rsbuild/plugin-
|
|
38
|
-
"@rsbuild/plugin-
|
|
39
|
-
"@rsbuild/plugin-
|
|
40
|
-
"@rsbuild/plugin-
|
|
41
|
-
"@rsbuild/plugin-
|
|
42
|
-
"@rsbuild/plugin-
|
|
43
|
-
"@rsbuild/plugin-
|
|
44
|
-
"@rsbuild/plugin-
|
|
45
|
-
"@rsbuild/plugin-
|
|
46
|
-
"@rsbuild/
|
|
47
|
-
"@rsbuild/shared": "0.7.10",
|
|
48
|
-
"@rsbuild/webpack": "0.7.10",
|
|
29
|
+
"@rsbuild/core": "1.0.1-beta.3",
|
|
30
|
+
"@rsbuild/plugin-sass": "1.0.1-beta.3",
|
|
31
|
+
"@rsbuild/plugin-less": "1.0.1-beta.3",
|
|
32
|
+
"@rsbuild/plugin-assets-retry": "1.0.1-beta.3",
|
|
33
|
+
"@rsbuild/plugin-babel": "1.0.1-beta.3",
|
|
34
|
+
"@rsbuild/plugin-check-syntax": "1.0.1-beta.3",
|
|
35
|
+
"@rsbuild/plugin-css-minimizer": "1.0.1",
|
|
36
|
+
"@rsbuild/plugin-pug": "1.0.1",
|
|
37
|
+
"@rsbuild/plugin-react": "1.0.1-beta.3",
|
|
38
|
+
"@rsbuild/plugin-rem": "1.0.1-beta.3",
|
|
39
|
+
"@rsbuild/plugin-source-build": "1.0.1-beta.3",
|
|
40
|
+
"@rsbuild/plugin-styled-components": "1.0.1-beta.3",
|
|
41
|
+
"@rsbuild/plugin-svgr": "1.0.1-beta.3",
|
|
42
|
+
"@rsbuild/plugin-type-check": "1.0.1-beta.3",
|
|
43
|
+
"@rsbuild/plugin-typed-css-modules": "1.0.1",
|
|
44
|
+
"@rsbuild/plugin-toml": "1.0.0",
|
|
45
|
+
"@rsbuild/plugin-yaml": "1.0.1",
|
|
46
|
+
"@rsbuild/webpack": "1.0.1-beta.3",
|
|
49
47
|
"@swc/helpers": "0.5.3",
|
|
50
48
|
"babel-loader": "9.1.3",
|
|
51
49
|
"babel-plugin-import": "1.13.5",
|
|
52
50
|
"babel-plugin-styled-components": "1.13.3",
|
|
53
51
|
"babel-plugin-transform-react-remove-prop-types": "0.4.24",
|
|
52
|
+
"browserslist": "4.23.1",
|
|
54
53
|
"cssnano": "6.0.1",
|
|
55
54
|
"glob": "^9.3.5",
|
|
56
55
|
"html-webpack-plugin": "5.5.3",
|
|
56
|
+
"html-minifier-terser": "^7.2.0",
|
|
57
57
|
"lodash": "^4.17.21",
|
|
58
58
|
"postcss": "^8.4.35",
|
|
59
59
|
"postcss-custom-properties": "13.1.5",
|
|
@@ -63,24 +63,29 @@
|
|
|
63
63
|
"postcss-media-minmax": "5.0.0",
|
|
64
64
|
"postcss-nesting": "12.0.1",
|
|
65
65
|
"postcss-page-break": "3.0.4",
|
|
66
|
+
"picocolors": "^1.0.1",
|
|
66
67
|
"react-refresh": "^0.14.0",
|
|
67
68
|
"rspack-manifest-plugin": "5.0.0",
|
|
68
69
|
"terser-webpack-plugin": "5.3.10",
|
|
70
|
+
"ts-deepmerge": "7.0.0",
|
|
69
71
|
"ts-loader": "9.4.4",
|
|
70
|
-
"webpack": "^5.
|
|
72
|
+
"webpack": "^5.93.0",
|
|
71
73
|
"webpack-subresource-integrity": "5.1.0",
|
|
72
|
-
"@modern-js/utils": "2.
|
|
73
|
-
"@modern-js/server": "2.
|
|
74
|
-
"@modern-js/
|
|
74
|
+
"@modern-js/utils": "2.56.0",
|
|
75
|
+
"@modern-js/server": "2.56.0",
|
|
76
|
+
"@modern-js/babel-preset": "2.56.0",
|
|
77
|
+
"@modern-js/prod-server": "2.56.0"
|
|
75
78
|
},
|
|
76
79
|
"devDependencies": {
|
|
77
|
-
"@rsbuild/plugin-swc": "0.
|
|
80
|
+
"@rsbuild/plugin-swc": "1.0.1-beta.3",
|
|
81
|
+
"@types/html-minifier-terser": "^7.0.2",
|
|
78
82
|
"@types/lodash": "^4.14.202",
|
|
79
83
|
"react": "^18.2.0",
|
|
80
84
|
"react-dom": "^18.2.0",
|
|
85
|
+
"terser": "^5.31.1",
|
|
81
86
|
"typescript": "^5.3.0",
|
|
82
|
-
"@scripts/build": "2.
|
|
83
|
-
"@scripts/vitest-config": "2.
|
|
87
|
+
"@scripts/build": "2.56.0",
|
|
88
|
+
"@scripts/vitest-config": "2.56.0"
|
|
84
89
|
},
|
|
85
90
|
"publishConfig": {
|
|
86
91
|
"access": "public",
|