@modern-js/uni-builder 0.0.0-nightly-20240708170628 → 0.0.0-nightly-20240710063815
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 -38
- 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/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 +18 -1
- package/dist/shared/utils.js +82 -0
- package/dist/types.d.ts +23 -3
- package/dist/webpack/ModuleScopePlugin.js +14 -4
- package/dist/webpack/plugins/babel.js +4 -4
- package/dist/webpack/plugins/tsLoader.d.ts +3 -1
- package/dist/webpack/plugins/tsLoader.js +2 -3
- 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 ConfigChain, type RsbuildPlugin, type ChainIdentifier, type RspackChain, 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,11 +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
|
|
53
|
+
var import_utils2 = require("./utils");
|
|
54
54
|
const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
|
|
55
55
|
const GLOBAL_CSS_REGEX = /\.global\.\w+$/;
|
|
56
56
|
const isLooseCssModules = (path) => {
|
|
57
|
-
if (
|
|
57
|
+
if (import_utils2.NODE_MODULES_REGEX.test(path)) {
|
|
58
58
|
return CSS_MODULES_REGEX.test(path);
|
|
59
59
|
}
|
|
60
60
|
return !GLOBAL_CSS_REGEX.test(path);
|
|
@@ -67,38 +67,6 @@ function removeUndefinedKey(obj) {
|
|
|
67
67
|
});
|
|
68
68
|
return obj;
|
|
69
69
|
}
|
|
70
|
-
const DEFAULT_WEB_BROWSERSLIST = [
|
|
71
|
-
"> 0.01%",
|
|
72
|
-
"not dead",
|
|
73
|
-
"not op_mini all"
|
|
74
|
-
];
|
|
75
|
-
const DEFAULT_BROWSERSLIST = {
|
|
76
|
-
web: DEFAULT_WEB_BROWSERSLIST,
|
|
77
|
-
node: [
|
|
78
|
-
"node >= 14"
|
|
79
|
-
],
|
|
80
|
-
"web-worker": DEFAULT_WEB_BROWSERSLIST,
|
|
81
|
-
"service-worker": DEFAULT_WEB_BROWSERSLIST
|
|
82
|
-
};
|
|
83
|
-
async function getBrowserslistWithDefault(path, config, target) {
|
|
84
|
-
const { overrideBrowserslist: overrides = {} } = (config === null || config === void 0 ? void 0 : config.output) || {};
|
|
85
|
-
if (target === "web" || target === "web-worker") {
|
|
86
|
-
if (Array.isArray(overrides)) {
|
|
87
|
-
return overrides;
|
|
88
|
-
}
|
|
89
|
-
if (overrides[target]) {
|
|
90
|
-
return overrides[target];
|
|
91
|
-
}
|
|
92
|
-
const browserslistrc = await (0, import_shared.getBrowserslist)(path);
|
|
93
|
-
if (browserslistrc) {
|
|
94
|
-
return browserslistrc;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (!Array.isArray(overrides) && overrides[target]) {
|
|
98
|
-
return overrides[target];
|
|
99
|
-
}
|
|
100
|
-
return DEFAULT_BROWSERSLIST[target];
|
|
101
|
-
}
|
|
102
70
|
const isUseCssSourceMap = (disableSourceMap = {}) => {
|
|
103
71
|
if (typeof disableSourceMap === "boolean") {
|
|
104
72
|
return !disableSourceMap;
|
|
@@ -175,7 +143,7 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
175
143
|
output.targets = targets;
|
|
176
144
|
const overrideBrowserslist = {};
|
|
177
145
|
for (const target2 of targets) {
|
|
178
|
-
overrideBrowserslist[target2] = await getBrowserslistWithDefault(cwd, uniBuilderConfig, target2);
|
|
146
|
+
overrideBrowserslist[target2] = await (0, import_utils2.getBrowserslistWithDefault)(cwd, uniBuilderConfig, target2);
|
|
179
147
|
}
|
|
180
148
|
output.overrideBrowserslist = overrideBrowserslist;
|
|
181
149
|
if (enableInlineStyles) {
|
|
@@ -216,10 +184,10 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
216
184
|
if (tagsByEntries) {
|
|
217
185
|
extraConfig.html.tags = [
|
|
218
186
|
(tags2, utils) => {
|
|
219
|
-
const entryTags = (0,
|
|
187
|
+
const entryTags = (0, import_utils2.castArray)(tagsByEntries[utils.entryName]);
|
|
220
188
|
const handlers = [];
|
|
221
189
|
for (const tag of entryTags) {
|
|
222
|
-
if ((0,
|
|
190
|
+
if ((0, import_utils.isFunction)(tag)) {
|
|
223
191
|
handlers.push(tag);
|
|
224
192
|
} else {
|
|
225
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;
|
|
@@ -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,7 +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";
|
|
3
4
|
export declare const JS_REGEX: RegExp;
|
|
4
5
|
export declare const TS_REGEX: RegExp;
|
|
6
|
+
export declare const SCRIPT_REGEX: RegExp;
|
|
7
|
+
export declare const NODE_MODULES_REGEX: RegExp;
|
|
5
8
|
export declare function isServerTarget(target: RsbuildTarget[]): boolean;
|
|
6
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;
|
|
7
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
|
@@ -19,16 +19,24 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var utils_exports = {};
|
|
20
20
|
__export(utils_exports, {
|
|
21
21
|
JS_REGEX: () => JS_REGEX,
|
|
22
|
+
NODE_MODULES_REGEX: () => NODE_MODULES_REGEX,
|
|
22
23
|
RUNTIME_CHUNK_NAME: () => RUNTIME_CHUNK_NAME,
|
|
24
|
+
SCRIPT_REGEX: () => SCRIPT_REGEX,
|
|
23
25
|
TS_REGEX: () => TS_REGEX,
|
|
26
|
+
applyScriptCondition: () => applyScriptCondition,
|
|
24
27
|
castArray: () => castArray,
|
|
28
|
+
getBrowserslistWithDefault: () => getBrowserslistWithDefault,
|
|
25
29
|
getHash: () => getHash,
|
|
30
|
+
isHtmlDisabled: () => isHtmlDisabled,
|
|
26
31
|
isServerTarget: () => isServerTarget
|
|
27
32
|
});
|
|
28
33
|
module.exports = __toCommonJS(utils_exports);
|
|
34
|
+
var import_shared = require("@rsbuild/shared");
|
|
29
35
|
const RUNTIME_CHUNK_NAME = "builder-runtime";
|
|
30
36
|
const JS_REGEX = /\.(?:js|mjs|cjs|jsx)$/;
|
|
31
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[\\/]/;
|
|
32
40
|
function isServerTarget(target) {
|
|
33
41
|
return (Array.isArray(target) ? target : [
|
|
34
42
|
target
|
|
@@ -45,6 +53,43 @@ const castArray = (arr) => {
|
|
|
45
53
|
arr
|
|
46
54
|
];
|
|
47
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
|
+
};
|
|
48
93
|
const getHash = (config) => {
|
|
49
94
|
const { filenameHash } = config.output;
|
|
50
95
|
if (typeof filenameHash === "string") {
|
|
@@ -52,12 +97,49 @@ const getHash = (config) => {
|
|
|
52
97
|
}
|
|
53
98
|
return filenameHash ? ".[contenthash:8]" : "";
|
|
54
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
|
+
}
|
|
55
132
|
// Annotate the CommonJS export names for ESM import in node:
|
|
56
133
|
0 && (module.exports = {
|
|
57
134
|
JS_REGEX,
|
|
135
|
+
NODE_MODULES_REGEX,
|
|
58
136
|
RUNTIME_CHUNK_NAME,
|
|
137
|
+
SCRIPT_REGEX,
|
|
59
138
|
TS_REGEX,
|
|
139
|
+
applyScriptCondition,
|
|
60
140
|
castArray,
|
|
141
|
+
getBrowserslistWithDefault,
|
|
61
142
|
getHash,
|
|
143
|
+
isHtmlDisabled,
|
|
62
144
|
isServerTarget
|
|
63
145
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { NodeEnv,
|
|
2
|
-
import type { ConfigChainWithContext, ConfigChain, DevConfig, RsbuildConfig, RsbuildTarget, Polyfill, ScriptInject, ServerConfig, RsbuildPluginAPI, SourceConfig, OutputConfig } from '@rsbuild/core';
|
|
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,6 +17,25 @@ 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
40
|
entry?: SourceConfig['entry'];
|
|
22
41
|
frameworkConfigPath?: string;
|
|
@@ -24,8 +43,9 @@ export type CreateBuilderCommonOptions = {
|
|
|
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>;
|
|
@@ -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,8 +1,9 @@
|
|
|
1
|
-
import { type FileFilterUtil } from '@rsbuild/shared';
|
|
2
1
|
import { type ConfigChainWithContext } from '@rsbuild/core';
|
|
3
2
|
import { PluginBabelOptions } from '@rsbuild/plugin-babel';
|
|
4
3
|
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
5
4
|
import type { Options as RawTSLoaderOptions } from 'ts-loader';
|
|
5
|
+
type OneOrMany<T> = T | T[];
|
|
6
|
+
type FileFilterUtil = (items: OneOrMany<string | RegExp>) => void;
|
|
6
7
|
export type TSLoaderOptions = Partial<RawTSLoaderOptions>;
|
|
7
8
|
export type PluginTsLoaderOptions = ConfigChainWithContext<TSLoaderOptions, {
|
|
8
9
|
/**
|
|
@@ -17,3 +18,4 @@ export type PluginTsLoaderOptions = ConfigChainWithContext<TSLoaderOptions, {
|
|
|
17
18
|
addExcludes: FileFilterUtil;
|
|
18
19
|
}>;
|
|
19
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,
|
|
@@ -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,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/uni-builder",
|
|
3
|
-
"version": "0.0.0-nightly-
|
|
3
|
+
"version": "0.0.0-nightly-20240710063815",
|
|
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/
|
|
73
|
-
"@modern-js/
|
|
74
|
-
"@modern-js/prod-server": "0.0.0-nightly-
|
|
75
|
+
"@modern-js/server": "0.0.0-nightly-20240710063815",
|
|
76
|
+
"@modern-js/utils": "0.0.0-nightly-20240710063815",
|
|
77
|
+
"@modern-js/prod-server": "0.0.0-nightly-20240710063815"
|
|
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": "0.0.0-nightly-20240710063815",
|
|
86
|
+
"@scripts/build": "0.0.0-nightly-20240710063815"
|
|
84
87
|
},
|
|
85
88
|
"publishConfig": {
|
|
86
89
|
"access": "public",
|