@modern-js/uni-builder 2.50.0 → 2.52.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 +1 -1
- package/dist/rspack/index.js +4 -1
- package/dist/shared/devServer.d.ts +4 -2
- package/dist/shared/devServer.js +12 -22
- package/dist/shared/parseCommonConfig.js +17 -3
- package/dist/shared/plugins/emitRouteFile.d.ts +1 -0
- package/dist/shared/plugins/emitRouteFile.js +6 -1
- package/dist/shared/plugins/fallback.js +2 -1
- package/dist/shared/plugins/globalVars.js +4 -8
- package/dist/shared/plugins/postcssLegacy.js +2 -1
- package/dist/types.d.ts +23 -11
- package/dist/webpack/index.d.ts +1 -2
- package/dist/webpack/index.js +1 -1
- package/dist/webpack/plugins/babel.js +3 -7
- package/dist/webpack/plugins/lazyCompilation.d.ts +3 -4
- package/dist/webpack/plugins/minimize.js +7 -5
- package/dist/webpack/plugins/moduleScopes.d.ts +3 -3
- package/dist/webpack/plugins/moduleScopes.js +2 -2
- package/dist/webpack/plugins/styledComponents.d.ts +2 -2
- package/dist/webpack/plugins/styledComponents.js +12 -4
- package/dist/webpack/plugins/tsLoader.d.ts +2 -2
- package/dist/webpack/plugins/tsLoader.js +6 -9
- package/package.json +27 -24
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ 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 { BundlerChain, RsbuildPlugin,
|
|
7
|
+
export type { BundlerChain, RsbuildPlugin, ConfigChain, CopyPluginOptions, ChainIdentifier, NormalizedConfig, RspackConfig, CacheGroup, } from '@rsbuild/shared';
|
|
8
8
|
export type { UniBuilderConfig, UniBuilderPlugin } from './types';
|
|
9
9
|
export type { StartDevServerOptions } from './shared/devServer';
|
|
10
10
|
export declare function createUniBuilder(options: CreateUniBuilderOptions): Promise<UniBuilderInstance>;
|
package/dist/rspack/index.js
CHANGED
|
@@ -36,8 +36,11 @@ var import_core = require("@rsbuild/core");
|
|
|
36
36
|
var import_parseCommonConfig = require("../shared/parseCommonConfig");
|
|
37
37
|
var import_compatLegacyPlugin = require("../shared/compatLegacyPlugin");
|
|
38
38
|
async function parseConfig(uniBuilderConfig, options) {
|
|
39
|
-
var _uniBuilderConfig_tools, _uniBuilderConfig_tools1;
|
|
39
|
+
var _uniBuilderConfig_experiments, _uniBuilderConfig_tools, _uniBuilderConfig_tools1;
|
|
40
40
|
const { rsbuildConfig, rsbuildPlugins } = await (0, import_parseCommonConfig.parseCommonConfig)(uniBuilderConfig, options);
|
|
41
|
+
if ((_uniBuilderConfig_experiments = uniBuilderConfig.experiments) === null || _uniBuilderConfig_experiments === void 0 ? void 0 : _uniBuilderConfig_experiments.lazyCompilation) {
|
|
42
|
+
rsbuildConfig.dev.lazyCompilation = uniBuilderConfig.experiments.lazyCompilation;
|
|
43
|
+
}
|
|
41
44
|
if ((_uniBuilderConfig_tools = uniBuilderConfig.tools) === null || _uniBuilderConfig_tools === void 0 ? void 0 : _uniBuilderConfig_tools.babel) {
|
|
42
45
|
var _uniBuilderConfig_tools2;
|
|
43
46
|
const { pluginBabel } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-babel")));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { StartDevServerOptions as RsbuildStartDevServerOptions,
|
|
2
|
+
import { StartDevServerOptions as RsbuildStartDevServerOptions, DevConfig, ServerConfig } from '@rsbuild/shared';
|
|
3
|
+
import type { RsbuildInstance } from '@rsbuild/core';
|
|
3
4
|
import type { ModernDevServerOptions } from '@modern-js/server';
|
|
4
5
|
import type { Server } from 'node:http';
|
|
5
6
|
import { type InitProdMiddlewares } from '@modern-js/prod-server';
|
|
@@ -16,8 +17,9 @@ export type StartDevServerOptions = RsbuildStartDevServerOptions & {
|
|
|
16
17
|
serverOptions?: ServerOptions;
|
|
17
18
|
initProdMiddlewares?: InitProdMiddlewares;
|
|
18
19
|
};
|
|
19
|
-
export type UniBuilderStartServerResult =
|
|
20
|
+
export type UniBuilderStartServerResult = {
|
|
20
21
|
server: Server;
|
|
22
|
+
port: number;
|
|
21
23
|
};
|
|
22
24
|
export declare function startDevServer(rsbuild: RsbuildInstance, options: StartDevServerOptions | undefined, builderConfig: UniBuilderConfig): Promise<UniBuilderStartServerResult>;
|
|
23
25
|
export {};
|
package/dist/shared/devServer.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(devServer_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(devServer_exports);
|
|
35
35
|
var import_shared = require("@rsbuild/shared");
|
|
36
|
+
var import_utils = require("@modern-js/utils");
|
|
36
37
|
var import_prod_server = require("@modern-js/prod-server");
|
|
37
38
|
const getServerOptions = (builderConfig) => {
|
|
38
39
|
var _builderConfig_output_distPath, _builderConfig_output, _builderConfig_output1, _builderConfig_output2;
|
|
@@ -58,22 +59,18 @@ const transformToRsbuildServerOptions = (dev, devServer) => {
|
|
|
58
59
|
var _newDevServerConfig_devMiddleware, _newDevServerConfig_before, _newDevServerConfig_after;
|
|
59
60
|
const { port = 8080, host, https, ...devConfig } = dev;
|
|
60
61
|
var _dev_hmr;
|
|
61
|
-
const newDevServerConfig = (0,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
writeToDisk: (file) => !file.includes(".hot-update.")
|
|
65
|
-
},
|
|
66
|
-
hot: (_dev_hmr = dev === null || dev === void 0 ? void 0 : dev.hmr) !== null && _dev_hmr !== void 0 ? _dev_hmr : true,
|
|
67
|
-
liveReload: true,
|
|
68
|
-
client: {
|
|
69
|
-
path: "/webpack-hmr",
|
|
70
|
-
overlay: false,
|
|
71
|
-
...devConfig.client || {}
|
|
72
|
-
}
|
|
62
|
+
const newDevServerConfig = (0, import_utils.applyOptionsChain)({
|
|
63
|
+
devMiddleware: {
|
|
64
|
+
writeToDisk: (file) => !file.includes(".hot-update.")
|
|
73
65
|
},
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
hot: (_dev_hmr = dev === null || dev === void 0 ? void 0 : dev.hmr) !== null && _dev_hmr !== void 0 ? _dev_hmr : true,
|
|
67
|
+
liveReload: true,
|
|
68
|
+
client: {
|
|
69
|
+
path: "/webpack-hmr",
|
|
70
|
+
overlay: false,
|
|
71
|
+
...devConfig.client || {}
|
|
72
|
+
}
|
|
73
|
+
}, devServer, {}, import_shared.deepmerge);
|
|
77
74
|
const rsbuildDev = {
|
|
78
75
|
...devConfig,
|
|
79
76
|
writeToDisk: (_newDevServerConfig_devMiddleware = newDevServerConfig.devMiddleware) === null || _newDevServerConfig_devMiddleware === void 0 ? void 0 : _newDevServerConfig_devMiddleware.writeToDisk,
|
|
@@ -162,12 +159,6 @@ async function startDevServer(rsbuild, options = {}, builderConfig) {
|
|
|
162
159
|
},
|
|
163
160
|
config
|
|
164
161
|
}, options.initProdMiddlewares);
|
|
165
|
-
const protocol = https ? "https" : "http";
|
|
166
|
-
const urls = (0, import_shared.getAddressUrls)({
|
|
167
|
-
protocol,
|
|
168
|
-
port,
|
|
169
|
-
host
|
|
170
|
-
});
|
|
171
162
|
(0, import_shared.debug)("listen dev server");
|
|
172
163
|
return new Promise((resolve) => {
|
|
173
164
|
server.listen({
|
|
@@ -181,7 +172,6 @@ async function startDevServer(rsbuild, options = {}, builderConfig) {
|
|
|
181
172
|
await rsbuildServer.afterListen();
|
|
182
173
|
resolve({
|
|
183
174
|
port,
|
|
184
|
-
urls: urls.map((item) => item.url),
|
|
185
175
|
server
|
|
186
176
|
});
|
|
187
177
|
});
|
|
@@ -47,11 +47,14 @@ var import_devtools = require("./plugins/devtools");
|
|
|
47
47
|
var import_emitRouteFile = require("./plugins/emitRouteFile");
|
|
48
48
|
var import_antd = require("./plugins/antd");
|
|
49
49
|
var import_arco = require("./plugins/arco");
|
|
50
|
+
var import_plugin_sass = require("@rsbuild/plugin-sass");
|
|
51
|
+
var import_plugin_less = require("@rsbuild/plugin-less");
|
|
50
52
|
var import_devServer = require("./devServer");
|
|
53
|
+
const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
|
|
51
54
|
const GLOBAL_CSS_REGEX = /\.global\.\w+$/;
|
|
52
55
|
const isLooseCssModules = (path) => {
|
|
53
56
|
if (import_shared.NODE_MODULES_REGEX.test(path)) {
|
|
54
|
-
return
|
|
57
|
+
return CSS_MODULES_REGEX.test(path);
|
|
55
58
|
}
|
|
56
59
|
return !GLOBAL_CSS_REGEX.test(path);
|
|
57
60
|
};
|
|
@@ -108,11 +111,12 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
108
111
|
var _uniBuilderConfig_output, _uniBuilderConfig_tools;
|
|
109
112
|
var _output, _output_distPath, _output_distPath1, _output1, _extraConfig, _html, _extraConfig1;
|
|
110
113
|
const { cwd, frameworkConfigPath, entry, target } = options;
|
|
111
|
-
const { plugins: [...plugins] = [], performance: { ...performanceConfig } = {}, output: { disableFilenameHash, enableLatestDecorators, cssModuleLocalIdentName, enableInlineScripts, disableCssExtract, enableInlineStyles, disableCssModuleExtension, disableTsChecker, disableSvgr, svgDefaultExport, assetsRetry, enableAssetFallback, enableAssetManifest, disableSourceMap, convertToRem, disableMinimize, polyfill, ...outputConfig } = {}, html: { disableHtmlFolder, metaByEntries, titleByEntries, faviconByEntries, injectByEntries, templateByEntries, templateParametersByEntries, tagsByEntries, tags, ...htmlConfig } = {}, source: { alias, globalVars, resolveMainFields, resolveExtensionPrefix, ...sourceConfig } = {}, dev, security: { checkSyntax, sri, ...securityConfig } = {}, tools: { devServer, tsChecker, minifyCss, ...toolsConfig } = {} } = uniBuilderConfig;
|
|
114
|
+
const { plugins: [...plugins] = [], performance: { ...performanceConfig } = {}, output: { disableFilenameHash, enableLatestDecorators, cssModuleLocalIdentName, enableInlineScripts, disableCssExtract, enableInlineStyles, enableCssModuleTSDeclaration, disableCssModuleExtension, disableTsChecker, disableSvgr, svgDefaultExport, assetsRetry, enableAssetFallback, enableAssetManifest, disableSourceMap, convertToRem, disableMinimize, polyfill, dataUriLimit = 1e4, ...outputConfig } = {}, html: { disableHtmlFolder, metaByEntries, titleByEntries, faviconByEntries, injectByEntries, templateByEntries, templateParametersByEntries, tagsByEntries, tags, ...htmlConfig } = {}, source: { alias, globalVars, resolveMainFields, resolveExtensionPrefix, ...sourceConfig } = {}, dev, security: { checkSyntax, sri, ...securityConfig } = {}, tools: { devServer, tsChecker, minifyCss, less, sass, ...toolsConfig } = {} } = uniBuilderConfig;
|
|
112
115
|
const rsbuildConfig = {
|
|
113
116
|
plugins,
|
|
114
117
|
output: {
|
|
115
118
|
polyfill: polyfill === "ua" ? "off" : polyfill,
|
|
119
|
+
dataUriLimit,
|
|
116
120
|
...outputConfig
|
|
117
121
|
},
|
|
118
122
|
source: {
|
|
@@ -260,7 +264,13 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
260
264
|
(0, import_plugin_toml.pluginToml)(),
|
|
261
265
|
(0, import_plugin_yaml.pluginYaml)(),
|
|
262
266
|
(0, import_antd.pluginAntd)(),
|
|
263
|
-
(0, import_arco.pluginArco)()
|
|
267
|
+
(0, import_arco.pluginArco)(),
|
|
268
|
+
(0, import_plugin_sass.pluginSass)({
|
|
269
|
+
sassLoaderOptions: sass
|
|
270
|
+
}),
|
|
271
|
+
(0, import_plugin_less.pluginLess)({
|
|
272
|
+
lessLoaderOptions: less
|
|
273
|
+
})
|
|
264
274
|
];
|
|
265
275
|
if (checkSyntax) {
|
|
266
276
|
const { pluginCheckSyntax } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-check-syntax")));
|
|
@@ -284,6 +294,10 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
284
294
|
const { pluginRem } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-rem")));
|
|
285
295
|
rsbuildPlugins.push(pluginRem(typeof convertToRem === "boolean" ? {} : convertToRem));
|
|
286
296
|
}
|
|
297
|
+
if (enableCssModuleTSDeclaration) {
|
|
298
|
+
const { pluginTypedCSSModules } = await Promise.resolve().then(() => __toESM(require("@rsbuild/plugin-typed-css-modules")));
|
|
299
|
+
rsbuildPlugins.push(pluginTypedCSSModules());
|
|
300
|
+
}
|
|
287
301
|
rsbuildPlugins.push((0, import_runtimeChunk.pluginRuntimeChunk)((_uniBuilderConfig_output = uniBuilderConfig.output) === null || _uniBuilderConfig_output === void 0 ? void 0 : _uniBuilderConfig_output.disableInlineRuntimeChunk));
|
|
288
302
|
const { sourceBuild } = uniBuilderConfig.experiments || {};
|
|
289
303
|
if (sourceBuild) {
|
|
@@ -28,11 +28,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var emitRouteFile_exports = {};
|
|
30
30
|
__export(emitRouteFile_exports, {
|
|
31
|
+
isFileExists: () => isFileExists,
|
|
31
32
|
pluginEmitRouteFile: () => pluginEmitRouteFile
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(emitRouteFile_exports);
|
|
34
35
|
var import_path = require("path");
|
|
35
36
|
var import_shared = require("@rsbuild/shared");
|
|
37
|
+
async function isFileExists(file) {
|
|
38
|
+
return import_shared.fse.promises.access(file, import_shared.fse.constants.F_OK).then(() => true).catch(() => false);
|
|
39
|
+
}
|
|
36
40
|
const pluginEmitRouteFile = () => ({
|
|
37
41
|
name: "uni-builder:emit-route-file",
|
|
38
42
|
setup(api) {
|
|
@@ -46,7 +50,7 @@ const pluginEmitRouteFile = () => ({
|
|
|
46
50
|
entryPath: filename,
|
|
47
51
|
isSPA: true
|
|
48
52
|
}));
|
|
49
|
-
if (!await
|
|
53
|
+
if (!await isFileExists(routeFilePath) && routesInfo.length) {
|
|
50
54
|
await fs.outputFile(routeFilePath, JSON.stringify({
|
|
51
55
|
routes: routesInfo
|
|
52
56
|
}, null, 2));
|
|
@@ -56,5 +60,6 @@ const pluginEmitRouteFile = () => ({
|
|
|
56
60
|
});
|
|
57
61
|
// Annotate the CommonJS export names for ESM import in node:
|
|
58
62
|
0 && (module.exports = {
|
|
63
|
+
isFileExists,
|
|
59
64
|
pluginEmitRouteFile
|
|
60
65
|
});
|
|
@@ -23,6 +23,7 @@ __export(fallback_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(fallback_exports);
|
|
24
24
|
var import_path = require("path");
|
|
25
25
|
var import_shared = require("@rsbuild/shared");
|
|
26
|
+
const HTML_REGEX = /\.html$/;
|
|
26
27
|
const resourceRuleFallback = (rules = []) => {
|
|
27
28
|
const innerRules = [];
|
|
28
29
|
const outerRules = [];
|
|
@@ -51,7 +52,7 @@ const resourceRuleFallback = (rules = []) => {
|
|
|
51
52
|
import_shared.JS_REGEX,
|
|
52
53
|
import_shared.TS_REGEX,
|
|
53
54
|
// exclude `html` and `json`, they get processed by webpack internal loaders.
|
|
54
|
-
|
|
55
|
+
HTML_REGEX,
|
|
55
56
|
/\.json$/
|
|
56
57
|
],
|
|
57
58
|
type: "asset/resource"
|
|
@@ -21,7 +21,7 @@ __export(globalVars_exports, {
|
|
|
21
21
|
pluginGlobalVars: () => pluginGlobalVars
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(globalVars_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_utils = require("@modern-js/utils");
|
|
25
25
|
const pluginGlobalVars = (options) => ({
|
|
26
26
|
name: "uni-builder:global-vars",
|
|
27
27
|
setup(api) {
|
|
@@ -29,13 +29,9 @@ const pluginGlobalVars = (options) => ({
|
|
|
29
29
|
if (!options) {
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
-
const globalVars = (0,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
utils: {
|
|
36
|
-
env,
|
|
37
|
-
target
|
|
38
|
-
}
|
|
32
|
+
const globalVars = (0, import_utils.applyOptionsChain)({}, options, {
|
|
33
|
+
env,
|
|
34
|
+
target
|
|
39
35
|
});
|
|
40
36
|
const serializedVars = {};
|
|
41
37
|
Object.entries(globalVars).forEach(([key, value]) => {
|
|
@@ -27,8 +27,9 @@ const pluginPostcssLegacy = (webBrowserslist) => ({
|
|
|
27
27
|
name: "uni-builder:postcss-plugins",
|
|
28
28
|
setup(api) {
|
|
29
29
|
api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {
|
|
30
|
+
var _config_output;
|
|
30
31
|
const cssSupport = (0, import_getCssSupport.getCssSupport)(webBrowserslist);
|
|
31
|
-
const enableExtractCSS = (
|
|
32
|
+
const enableExtractCSS = !((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.injectStyles);
|
|
32
33
|
const enableCssMinify = !enableExtractCSS && import_shared.isProd;
|
|
33
34
|
const plugins = [
|
|
34
35
|
require("postcss-flexbugs-fixes"),
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { NodeEnv, MetaOptions,
|
|
2
|
-
import type { RsbuildConfig } from '@rsbuild/core';
|
|
1
|
+
import type { NodeEnv, MetaOptions, ConfigChain, ConfigChainWithContext, InlineChunkTest, RequestHandler, MaybePromise, HtmlTagDescriptor } from '@rsbuild/shared';
|
|
2
|
+
import type { DevConfig, RsbuildConfig, RsbuildTarget, Polyfill, ScriptInject, RsbuildEntry, ServerConfig, RsbuildPluginAPI } from '@rsbuild/core';
|
|
3
3
|
import type { PluginAssetsRetryOptions } from '@rsbuild/plugin-assets-retry';
|
|
4
4
|
import type { PluginStyledComponentsOptions } from '@rsbuild/plugin-styled-components';
|
|
5
|
-
import type { LazyCompilationOptions } from './webpack/plugins/lazyCompilation';
|
|
6
5
|
import type { PluginRemOptions } from '@rsbuild/plugin-rem';
|
|
7
6
|
import type { PluginTsLoaderOptions } from './webpack/plugins/tsLoader';
|
|
8
7
|
import type { SvgDefaultExport } from '@rsbuild/plugin-svgr';
|
|
@@ -11,10 +10,13 @@ import type { PluginTypeCheckerOptions } from '@rsbuild/plugin-type-check';
|
|
|
11
10
|
import type { PluginCheckSyntaxOptions } from '@rsbuild/plugin-check-syntax';
|
|
12
11
|
import type { PluginPugOptions } from '@rsbuild/plugin-pug';
|
|
13
12
|
import type { PluginBabelOptions } from '@rsbuild/plugin-babel';
|
|
13
|
+
import type { PluginSassOptions } from '@rsbuild/plugin-sass';
|
|
14
|
+
import type { PluginLessOptions } from '@rsbuild/plugin-less';
|
|
14
15
|
import type { AliasOption } from '@modern-js/utils';
|
|
15
16
|
import type { StartDevServerOptions, UniBuilderStartServerResult } from './shared/devServer';
|
|
16
17
|
import type { PluginSourceBuildOptions } from '@rsbuild/plugin-source-build';
|
|
17
18
|
import type TerserPlugin from 'terser-webpack-plugin';
|
|
19
|
+
type ArrayOrNot<T> = T | T[];
|
|
18
20
|
export type CreateBuilderCommonOptions = {
|
|
19
21
|
entry?: RsbuildEntry;
|
|
20
22
|
frameworkConfigPath?: string;
|
|
@@ -27,7 +29,7 @@ export type CreateUniBuilderOptions = {
|
|
|
27
29
|
config: UniBuilderConfig;
|
|
28
30
|
} & Partial<CreateBuilderCommonOptions>;
|
|
29
31
|
export type GlobalVars = Record<string, any>;
|
|
30
|
-
export type ChainedGlobalVars =
|
|
32
|
+
export type ChainedGlobalVars = ConfigChainWithContext<GlobalVars, {
|
|
31
33
|
env: NodeEnv;
|
|
32
34
|
target: RsbuildTarget;
|
|
33
35
|
}>;
|
|
@@ -41,7 +43,7 @@ export type DisableSourceMapOption = boolean | {
|
|
|
41
43
|
js?: boolean;
|
|
42
44
|
css?: boolean;
|
|
43
45
|
};
|
|
44
|
-
export type ToolsDevServerConfig =
|
|
46
|
+
export type ToolsDevServerConfig = ConfigChain<{
|
|
45
47
|
before?: RequestHandler[];
|
|
46
48
|
after?: RequestHandler[];
|
|
47
49
|
client?: DevConfig['client'];
|
|
@@ -58,7 +60,7 @@ export type ToolsDevServerConfig = ChainedConfig<{
|
|
|
58
60
|
proxy?: ServerConfig['proxy'];
|
|
59
61
|
}>;
|
|
60
62
|
export type TerserPluginOptions = TerserPlugin.BasePluginOptions & TerserPlugin.DefinedDefaultMinimizerAndOptions<TerserPlugin.TerserOptions>;
|
|
61
|
-
export type ToolsTerserConfig =
|
|
63
|
+
export type ToolsTerserConfig = ConfigChain<TerserPluginOptions>;
|
|
62
64
|
export type UniBuilderExtraConfig = {
|
|
63
65
|
tools?: {
|
|
64
66
|
styledComponents?: false | PluginStyledComponentsOptions;
|
|
@@ -94,6 +96,14 @@ export type UniBuilderExtraConfig = {
|
|
|
94
96
|
* @requires webpack
|
|
95
97
|
*/
|
|
96
98
|
terser?: ToolsTerserConfig;
|
|
99
|
+
/**
|
|
100
|
+
* Modify the config of [less-loader](https://github.com/webpack-contrib/less-loader).
|
|
101
|
+
*/
|
|
102
|
+
less?: PluginLessOptions['lessLoaderOptions'];
|
|
103
|
+
/**
|
|
104
|
+
* Modify the config of [sass-loader](https://github.com/webpack-contrib/sass-loader).
|
|
105
|
+
*/
|
|
106
|
+
sass?: PluginSassOptions['sassLoaderOptions'];
|
|
97
107
|
};
|
|
98
108
|
dev?: {
|
|
99
109
|
/**
|
|
@@ -119,7 +129,7 @@ export type UniBuilderExtraConfig = {
|
|
|
119
129
|
* Restrict importing paths. After configuring this option, all source files can only import code from
|
|
120
130
|
* the specific paths, and import code from other paths is not allowed.
|
|
121
131
|
*/
|
|
122
|
-
moduleScopes?:
|
|
132
|
+
moduleScopes?: ConfigChain<ModuleScopes>;
|
|
123
133
|
/**
|
|
124
134
|
* This configuration will determine which field of `package.json` you use to import the `npm` module.
|
|
125
135
|
* Same as the [resolve.mainFields](https://webpack.js.org/configuration/resolve/#resolvemainfields) config of webpack.
|
|
@@ -139,6 +149,10 @@ export type UniBuilderExtraConfig = {
|
|
|
139
149
|
* @deprecated use `output.filenameHash` instead
|
|
140
150
|
*/
|
|
141
151
|
disableFilenameHash?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Whether to generate a TypeScript declaration file for CSS Modules.
|
|
154
|
+
*/
|
|
155
|
+
enableCssModuleTSDeclaration?: boolean;
|
|
142
156
|
/**
|
|
143
157
|
* @deprecated use `source.decorators` instead
|
|
144
158
|
*/
|
|
@@ -260,10 +274,7 @@ export type UniBuilderExtraConfig = {
|
|
|
260
274
|
checkSyntax?: boolean | PluginCheckSyntaxOptions;
|
|
261
275
|
};
|
|
262
276
|
experiments?: {
|
|
263
|
-
|
|
264
|
-
* Tips: this configuration is not yet supported in rspack
|
|
265
|
-
*/
|
|
266
|
-
lazyCompilation?: LazyCompilationOptions;
|
|
277
|
+
lazyCompilation?: DevConfig['lazyCompilation'];
|
|
267
278
|
/**
|
|
268
279
|
* Enable the ability for source code building
|
|
269
280
|
*/
|
|
@@ -333,3 +344,4 @@ export type UniBuilderConfig = {
|
|
|
333
344
|
source?: Omit<NonNullable<RsbuildConfig['source']>, 'alias'>;
|
|
334
345
|
plugins?: RsbuildConfig['plugins'];
|
|
335
346
|
} & UniBuilderExtraConfig;
|
|
347
|
+
export {};
|
package/dist/webpack/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { type RsbuildConfig, type RsbuildPlugin, type RsbuildInstance } from '@rsbuild/core';
|
|
2
|
-
import type { RsbuildProvider } from '@rsbuild/shared';
|
|
3
2
|
import type { UniBuilderConfig, CreateUniBuilderOptions, CreateBuilderCommonOptions, OverridesUniBuilderInstance } from '../types';
|
|
4
3
|
export declare function parseConfig(uniBuilderConfig: UniBuilderConfig, options: CreateBuilderCommonOptions): Promise<{
|
|
5
4
|
rsbuildConfig: RsbuildConfig;
|
|
6
5
|
rsbuildPlugins: RsbuildPlugin[];
|
|
7
6
|
}>;
|
|
8
|
-
export type UniBuilderWebpackInstance = Omit<RsbuildInstance
|
|
7
|
+
export type UniBuilderWebpackInstance = Omit<RsbuildInstance, keyof OverridesUniBuilderInstance> & OverridesUniBuilderInstance;
|
|
9
8
|
export declare function createWebpackBuilder(options: CreateUniBuilderOptions): Promise<UniBuilderWebpackInstance>;
|
package/dist/webpack/index.js
CHANGED
|
@@ -85,7 +85,7 @@ async function createWebpackBuilder(options) {
|
|
|
85
85
|
cwd
|
|
86
86
|
});
|
|
87
87
|
const { webpackProvider } = await Promise.resolve().then(() => __toESM(require("@rsbuild/webpack")));
|
|
88
|
-
const { setHTMLPlugin } = await Promise.resolve().then(() => __toESM(require("@rsbuild/core
|
|
88
|
+
const { __internalHelper: { setHTMLPlugin } } = await Promise.resolve().then(() => __toESM(require("@rsbuild/core")));
|
|
89
89
|
const { default: HtmlWebpackPlugin } = await Promise.resolve().then(() => __toESM(require("html-webpack-plugin")));
|
|
90
90
|
setHTMLPlugin(HtmlWebpackPlugin);
|
|
91
91
|
rsbuildConfig.provider = webpackProvider;
|
|
@@ -113,13 +113,9 @@ const pluginBabel = (options, extraOptions) => ({
|
|
|
113
113
|
}
|
|
114
114
|
]);
|
|
115
115
|
}
|
|
116
|
-
const babelConfig = (0,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
utils: {
|
|
120
|
-
...(0, import_plugin_babel.getBabelUtils)(baseBabelConfig),
|
|
121
|
-
...babelUtils
|
|
122
|
-
}
|
|
116
|
+
const babelConfig = (0, import_utils.applyOptionsChain)(baseBabelConfig, options === null || options === void 0 ? void 0 : options.babelLoaderOptions, {
|
|
117
|
+
...(0, import_plugin_babel.getBabelUtils)(baseBabelConfig),
|
|
118
|
+
...babelUtils
|
|
123
119
|
});
|
|
124
120
|
const finalOptions = {
|
|
125
121
|
babelrc: false,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
imports?: boolean;
|
|
5
|
-
};
|
|
2
|
+
import type { DevConfig } from '@rsbuild/shared';
|
|
3
|
+
type LazyCompilationOptions = DevConfig['lazyCompilation'];
|
|
6
4
|
export declare const pluginLazyCompilation: (options: LazyCompilationOptions) => RsbuildPlugin;
|
|
5
|
+
export {};
|
|
@@ -32,6 +32,7 @@ __export(minimize_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(minimize_exports);
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
|
+
var import_utils = require("@modern-js/utils");
|
|
35
36
|
function applyRemoveConsole(options, config) {
|
|
36
37
|
const { removeConsole } = config.performance;
|
|
37
38
|
const compressOptions = typeof options.terserOptions.compress === "boolean" ? {} : options.terserOptions.compress || {};
|
|
@@ -76,10 +77,7 @@ async function applyJSMinimizer(chain, config, userTerserConfig) {
|
|
|
76
77
|
default:
|
|
77
78
|
break;
|
|
78
79
|
}
|
|
79
|
-
const mergedOptions = (0,
|
|
80
|
-
defaults: DEFAULT_OPTIONS,
|
|
81
|
-
options: userTerserConfig
|
|
82
|
-
});
|
|
80
|
+
const mergedOptions = (0, import_utils.applyOptionsChain)(DEFAULT_OPTIONS, userTerserConfig);
|
|
83
81
|
chain.optimization.minimizer(import_shared.CHAIN_ID.MINIMIZER.JS).use(TerserPlugin, [
|
|
84
82
|
// Due to terser-webpack-plugin has changed the type of class, which using a generic type in
|
|
85
83
|
// constructor, leading auto inference of parameters of plugin constructor is not possible, using any instead
|
|
@@ -91,7 +89,11 @@ const pluginMinimize = (userTerserConfig) => ({
|
|
|
91
89
|
setup(api) {
|
|
92
90
|
api.modifyBundlerChain(async (chain, { isProd }) => {
|
|
93
91
|
const config = api.getNormalizedConfig();
|
|
94
|
-
|
|
92
|
+
const { minify } = config.output;
|
|
93
|
+
if (minify === false || !isProd) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (minify === true || (minify === null || minify === void 0 ? void 0 : minify.js) !== false) {
|
|
95
97
|
await applyJSMinimizer(chain, config, userTerserConfig);
|
|
96
98
|
}
|
|
97
99
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
import { type
|
|
2
|
+
import { type ConfigChain } from '@rsbuild/shared';
|
|
3
3
|
import type { ModuleScopes } from '../../types';
|
|
4
4
|
export declare const isPrimitiveScope: (items: unknown[]) => items is (string | RegExp)[];
|
|
5
|
-
export declare const applyScopeChain: (defaults: ModuleScopes, options:
|
|
6
|
-
export declare const pluginModuleScopes: (moduleScopes?:
|
|
5
|
+
export declare const applyScopeChain: (defaults: ModuleScopes, options: ConfigChain<ModuleScopes>) => ModuleScopes;
|
|
6
|
+
export declare const pluginModuleScopes: (moduleScopes?: ConfigChain<ModuleScopes>) => RsbuildPlugin;
|
|
@@ -34,7 +34,7 @@ __export(moduleScopes_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(moduleScopes_exports);
|
|
36
36
|
var import_path = __toESM(require("path"));
|
|
37
|
-
|
|
37
|
+
const ensureAbsolutePath = (base, filePath) => import_path.default.isAbsolute(filePath) ? filePath : import_path.default.resolve(base, filePath);
|
|
38
38
|
const isPrimitiveScope = (items) => items.every((item) => typeof item === "string" || Object.prototype.toString.call(item) === "[object RegExp]");
|
|
39
39
|
const applyScopeChain = (defaults, options) => {
|
|
40
40
|
if (Array.isArray(options)) {
|
|
@@ -57,7 +57,7 @@ const pluginModuleScopes = (moduleScopes) => ({
|
|
|
57
57
|
const rootPackageJson = import_path.default.resolve(api.context.rootPath, "./package.json");
|
|
58
58
|
const formattedScopes = scopes.map((scope) => {
|
|
59
59
|
if (typeof scope === "string") {
|
|
60
|
-
return
|
|
60
|
+
return ensureAbsolutePath(api.context.rootPath, scope);
|
|
61
61
|
}
|
|
62
62
|
return scope;
|
|
63
63
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
import { type
|
|
2
|
+
import { type ConfigChain } from '@rsbuild/shared';
|
|
3
3
|
import type { PluginStyledComponentsOptions } from '@rsbuild/plugin-styled-components';
|
|
4
|
-
export declare const pluginStyledComponents: (userConfig?:
|
|
4
|
+
export declare const pluginStyledComponents: (userConfig?: ConfigChain<PluginStyledComponentsOptions>) => RsbuildPlugin;
|
|
@@ -33,6 +33,17 @@ __export(styledComponents_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(styledComponents_exports);
|
|
34
34
|
var import_core = require("@rsbuild/core");
|
|
35
35
|
var import_shared = require("@rsbuild/shared");
|
|
36
|
+
var import_utils = require("@modern-js/utils");
|
|
37
|
+
const getDefaultStyledComponentsConfig = (isProd, ssr) => {
|
|
38
|
+
return {
|
|
39
|
+
ssr,
|
|
40
|
+
// "pure" is used to improve dead code elimination in production.
|
|
41
|
+
// we don't need to enable it in development because it will slow down the build process.
|
|
42
|
+
pure: isProd,
|
|
43
|
+
displayName: true,
|
|
44
|
+
transpileTemplateLiterals: true
|
|
45
|
+
};
|
|
46
|
+
};
|
|
36
47
|
const pluginStyledComponents = (userConfig = {}) => ({
|
|
37
48
|
name: "uni-builder:styled-components",
|
|
38
49
|
pre: [
|
|
@@ -42,10 +53,7 @@ const pluginStyledComponents = (userConfig = {}) => ({
|
|
|
42
53
|
setup(api) {
|
|
43
54
|
api.modifyBundlerChain(async (chain, { CHAIN_ID, isProd }) => {
|
|
44
55
|
const isSSR = (0, import_shared.isServerTarget)(api.context.targets);
|
|
45
|
-
const styledComponentsOptions = (0,
|
|
46
|
-
defaults: (0, import_shared.getDefaultStyledComponentsConfig)(isProd, isSSR),
|
|
47
|
-
options: userConfig
|
|
48
|
-
});
|
|
56
|
+
const styledComponentsOptions = (0, import_utils.applyOptionsChain)(getDefaultStyledComponentsConfig(isProd, isSSR), userConfig);
|
|
49
57
|
if (!styledComponentsOptions) {
|
|
50
58
|
return;
|
|
51
59
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { type FileFilterUtil, type
|
|
1
|
+
import { type FileFilterUtil, type ConfigChainWithContext } from '@rsbuild/shared';
|
|
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
5
|
export type TSLoaderOptions = Partial<RawTSLoaderOptions>;
|
|
6
|
-
export type PluginTsLoaderOptions =
|
|
6
|
+
export type PluginTsLoaderOptions = ConfigChainWithContext<TSLoaderOptions, {
|
|
7
7
|
/**
|
|
8
8
|
* use `source.include` instead
|
|
9
9
|
* @deprecated
|
|
@@ -32,6 +32,7 @@ __export(tsLoader_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(tsLoader_exports);
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
|
+
var import_utils = require("@modern-js/utils");
|
|
35
36
|
var import_plugin_babel = require("@rsbuild/plugin-babel");
|
|
36
37
|
var import_web = require("@rsbuild/babel-preset/web");
|
|
37
38
|
var import_babel = require("./babel");
|
|
@@ -57,11 +58,7 @@ const pluginTsLoader = (options, babelOptions) => {
|
|
|
57
58
|
});
|
|
58
59
|
(_baseBabelConfig_presets = baseBabelConfig.presets) === null || _baseBabelConfig_presets === void 0 ? void 0 : _baseBabelConfig_presets.push((0, import_babel.getPresetReact)(api.context.rootPath, isProd));
|
|
59
60
|
const babelUtils = (0, import_plugin_babel.getBabelUtils)(baseBabelConfig);
|
|
60
|
-
const babelLoaderOptions = (0,
|
|
61
|
-
defaults: baseBabelConfig,
|
|
62
|
-
options: babelOptions,
|
|
63
|
-
utils: babelUtils
|
|
64
|
-
});
|
|
61
|
+
const babelLoaderOptions = (0, import_utils.applyOptionsChain)(baseBabelConfig, babelOptions, babelUtils);
|
|
65
62
|
const includes = [];
|
|
66
63
|
const excludes = [];
|
|
67
64
|
const tsLoaderUtils = {
|
|
@@ -80,12 +77,12 @@ const pluginTsLoader = (options, babelOptions) => {
|
|
|
80
77
|
transpileOnly: true,
|
|
81
78
|
allowTsInNodeModules: true
|
|
82
79
|
};
|
|
83
|
-
const tsLoaderOptions = (0,
|
|
84
|
-
defaults: tsLoaderDefaultOptions,
|
|
80
|
+
const tsLoaderOptions = (0, import_utils.applyOptionsChain)(
|
|
85
81
|
// @ts-expect-error ts-loader has incorrect types for compilerOptions
|
|
82
|
+
tsLoaderDefaultOptions,
|
|
86
83
|
options,
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
tsLoaderUtils
|
|
85
|
+
);
|
|
89
86
|
const rule = chain.module.rule(CHAIN_ID.RULE.TS);
|
|
90
87
|
(0, import_shared.applyScriptCondition)({
|
|
91
88
|
chain,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/uni-builder",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.52.0",
|
|
4
4
|
"description": "Unified builder for Modern.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,23 +26,26 @@
|
|
|
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.
|
|
30
|
-
"@rsbuild/core": "0.
|
|
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/
|
|
45
|
-
"@rsbuild/
|
|
29
|
+
"@rsbuild/babel-preset": "0.7.3",
|
|
30
|
+
"@rsbuild/core": "0.7.3",
|
|
31
|
+
"@rsbuild/plugin-sass": "0.7.3",
|
|
32
|
+
"@rsbuild/plugin-less": "0.7.3",
|
|
33
|
+
"@rsbuild/plugin-assets-retry": "0.7.3",
|
|
34
|
+
"@rsbuild/plugin-babel": "0.7.3",
|
|
35
|
+
"@rsbuild/plugin-check-syntax": "0.7.3",
|
|
36
|
+
"@rsbuild/plugin-css-minimizer": "0.7.3",
|
|
37
|
+
"@rsbuild/plugin-pug": "0.7.3",
|
|
38
|
+
"@rsbuild/plugin-react": "0.7.3",
|
|
39
|
+
"@rsbuild/plugin-rem": "0.7.3",
|
|
40
|
+
"@rsbuild/plugin-source-build": "0.7.3",
|
|
41
|
+
"@rsbuild/plugin-styled-components": "0.7.3",
|
|
42
|
+
"@rsbuild/plugin-svgr": "0.7.3",
|
|
43
|
+
"@rsbuild/plugin-type-check": "0.7.3",
|
|
44
|
+
"@rsbuild/plugin-typed-css-modules": "0.7.3",
|
|
45
|
+
"@rsbuild/plugin-toml": "0.7.3",
|
|
46
|
+
"@rsbuild/plugin-yaml": "0.7.3",
|
|
47
|
+
"@rsbuild/shared": "0.7.3",
|
|
48
|
+
"@rsbuild/webpack": "0.7.3",
|
|
46
49
|
"@swc/helpers": "0.5.3",
|
|
47
50
|
"babel-loader": "9.1.3",
|
|
48
51
|
"babel-plugin-import": "1.13.5",
|
|
@@ -66,18 +69,18 @@
|
|
|
66
69
|
"ts-loader": "9.4.4",
|
|
67
70
|
"webpack": "^5.91.0",
|
|
68
71
|
"webpack-subresource-integrity": "5.1.0",
|
|
69
|
-
"@modern-js/
|
|
70
|
-
"@modern-js/
|
|
71
|
-
"@modern-js/
|
|
72
|
+
"@modern-js/utils": "2.52.0",
|
|
73
|
+
"@modern-js/server": "2.52.0",
|
|
74
|
+
"@modern-js/prod-server": "2.52.0"
|
|
72
75
|
},
|
|
73
76
|
"devDependencies": {
|
|
74
|
-
"@rsbuild/plugin-swc": "0.
|
|
77
|
+
"@rsbuild/plugin-swc": "0.7.3",
|
|
75
78
|
"@types/lodash": "^4.14.202",
|
|
76
79
|
"react": "^18.2.0",
|
|
77
80
|
"react-dom": "^18.2.0",
|
|
78
81
|
"typescript": "^5.3.0",
|
|
79
|
-
"@scripts/build": "2.
|
|
80
|
-
"@scripts/vitest-config": "2.
|
|
82
|
+
"@scripts/build": "2.52.0",
|
|
83
|
+
"@scripts/vitest-config": "2.52.0"
|
|
81
84
|
},
|
|
82
85
|
"publishConfig": {
|
|
83
86
|
"access": "public",
|