@modern-js/uni-builder 0.0.0-nightly-20240707170654 → 0.0.0-nightly-20240708170628
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 +2 -2
- package/dist/shared/parseCommonConfig.js +2 -1
- package/dist/shared/plugins/fallback.js +13 -20
- package/dist/shared/utils.d.ts +2 -0
- package/dist/shared/utils.js +13 -0
- package/dist/types.d.ts +6 -6
- package/dist/webpack/plugins/babel.d.ts +1 -1
- package/dist/webpack/plugins/lazyCompilation.d.ts +1 -2
- package/dist/webpack/plugins/minimize.d.ts +1 -1
- package/dist/webpack/plugins/minimize.js +4 -5
- package/dist/webpack/plugins/moduleScopes.d.ts +1 -2
- package/dist/webpack/plugins/react.js +2 -2
- package/dist/webpack/plugins/styledComponents.d.ts +1 -2
- package/dist/webpack/plugins/tsLoader.d.ts +2 -1
- package/dist/webpack/plugins/tsLoader.js +3 -3
- package/package.json +6 -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 {
|
|
7
|
+
export type { CopyPluginOptions, 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>;
|
|
11
|
-
export { logger, type Rspack, type RsbuildContext, type RsbuildConfig, } from '@rsbuild/core';
|
|
11
|
+
export { logger, type ConfigChain, type RsbuildPlugin, type ChainIdentifier, type RspackChain, type Rspack, type RsbuildContext, type RsbuildConfig, } from '@rsbuild/core';
|
|
12
12
|
export type { webpack, WebpackConfig } from '@rsbuild/webpack';
|
|
13
13
|
export { RUNTIME_CHUNK_NAME } from './shared/utils';
|
|
@@ -50,6 +50,7 @@ var import_arco = require("./plugins/arco");
|
|
|
50
50
|
var import_plugin_sass = require("@rsbuild/plugin-sass");
|
|
51
51
|
var import_plugin_less = require("@rsbuild/plugin-less");
|
|
52
52
|
var import_devServer = require("./devServer");
|
|
53
|
+
var import_utils = require("./utils");
|
|
53
54
|
const CSS_MODULES_REGEX = /\.modules?\.\w+$/i;
|
|
54
55
|
const GLOBAL_CSS_REGEX = /\.global\.\w+$/;
|
|
55
56
|
const isLooseCssModules = (path) => {
|
|
@@ -215,7 +216,7 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
215
216
|
if (tagsByEntries) {
|
|
216
217
|
extraConfig.html.tags = [
|
|
217
218
|
(tags2, utils) => {
|
|
218
|
-
const entryTags = (0,
|
|
219
|
+
const entryTags = (0, import_utils.castArray)(tagsByEntries[utils.entryName]);
|
|
219
220
|
const handlers = [];
|
|
220
221
|
for (const tag of entryTags) {
|
|
221
222
|
if ((0, import_shared.isFunction)(tag)) {
|
|
@@ -22,7 +22,6 @@ __export(fallback_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(fallback_exports);
|
|
24
24
|
var import_path = require("path");
|
|
25
|
-
var import_shared = require("@rsbuild/shared");
|
|
26
25
|
var import_utils = require("../../shared/utils");
|
|
27
26
|
const HTML_REGEX = /\.html$/;
|
|
28
27
|
const resourceRuleFallback = (rules = []) => {
|
|
@@ -50,7 +49,7 @@ const resourceRuleFallback = (rules = []) => {
|
|
|
50
49
|
}
|
|
51
50
|
const fileLoader = {
|
|
52
51
|
exclude: [
|
|
53
|
-
|
|
52
|
+
import_utils.JS_REGEX,
|
|
54
53
|
import_utils.TS_REGEX,
|
|
55
54
|
// exclude `html` and `json`, they get processed by webpack internal loaders.
|
|
56
55
|
HTML_REGEX,
|
|
@@ -71,17 +70,17 @@ const resourceRuleFallback = (rules = []) => {
|
|
|
71
70
|
const pluginFallback = () => ({
|
|
72
71
|
name: "uni-builder:fallback",
|
|
73
72
|
setup(api) {
|
|
74
|
-
|
|
75
|
-
api.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
assetModuleFilename: (0, import_path.join)(distDir, mediaFilename)
|
|
83
|
-
});
|
|
73
|
+
api.modifyBundlerChain((chain) => {
|
|
74
|
+
const rsbuildConfig = api.getNormalizedConfig();
|
|
75
|
+
const { distPath, filename } = rsbuildConfig.output;
|
|
76
|
+
const distDir = distPath.media;
|
|
77
|
+
var _filename_media;
|
|
78
|
+
const mediaFilename = (_filename_media = filename.media) !== null && _filename_media !== void 0 ? _filename_media : `[name]${(0, import_utils.getHash)(rsbuildConfig)}[ext]`;
|
|
79
|
+
chain.output.merge({
|
|
80
|
+
assetModuleFilename: (0, import_path.join)(distDir, mediaFilename)
|
|
84
81
|
});
|
|
82
|
+
});
|
|
83
|
+
if (api.context.bundlerType === "webpack") {
|
|
85
84
|
api.modifyWebpackConfig((config) => {
|
|
86
85
|
if (!config.module) {
|
|
87
86
|
return;
|
|
@@ -91,17 +90,11 @@ const pluginFallback = () => ({
|
|
|
91
90
|
} else {
|
|
92
91
|
api.modifyRspackConfig((config) => {
|
|
93
92
|
var _config_module;
|
|
94
|
-
var _config
|
|
95
|
-
const rsbuildConfig = api.getNormalizedConfig();
|
|
96
|
-
const distDir = rsbuildConfig.output.distPath.media;
|
|
97
|
-
var _rsbuildConfig_output_filename_media;
|
|
98
|
-
const filename = (_rsbuildConfig_output_filename_media = rsbuildConfig.output.filename.media) !== null && _rsbuildConfig_output_filename_media !== void 0 ? _rsbuildConfig_output_filename_media : `[name]${(0, import_utils.getHash)(rsbuildConfig)}[ext]`;
|
|
99
|
-
(_config = config).output || (_config.output = {});
|
|
100
|
-
config.output.assetModuleFilename = (0, import_path.join)(distDir, filename);
|
|
93
|
+
var _config;
|
|
101
94
|
if (!config.module) {
|
|
102
95
|
return;
|
|
103
96
|
}
|
|
104
|
-
(
|
|
97
|
+
(_config = config).module || (_config.module = {});
|
|
105
98
|
config.module.rules = resourceRuleFallback((_config_module = config.module) === null || _config_module === void 0 ? void 0 : _config_module.rules);
|
|
106
99
|
});
|
|
107
100
|
}
|
package/dist/shared/utils.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { RsbuildTarget, NormalizedConfig } from '@rsbuild/core';
|
|
2
2
|
export declare const RUNTIME_CHUNK_NAME = "builder-runtime";
|
|
3
|
+
export declare const JS_REGEX: RegExp;
|
|
3
4
|
export declare const TS_REGEX: RegExp;
|
|
4
5
|
export declare function isServerTarget(target: RsbuildTarget[]): boolean;
|
|
6
|
+
export declare const castArray: <T>(arr?: T | T[] | undefined) => T[];
|
|
5
7
|
export declare const getHash: (config: NormalizedConfig) => string;
|
package/dist/shared/utils.js
CHANGED
|
@@ -18,13 +18,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var utils_exports = {};
|
|
20
20
|
__export(utils_exports, {
|
|
21
|
+
JS_REGEX: () => JS_REGEX,
|
|
21
22
|
RUNTIME_CHUNK_NAME: () => RUNTIME_CHUNK_NAME,
|
|
22
23
|
TS_REGEX: () => TS_REGEX,
|
|
24
|
+
castArray: () => castArray,
|
|
23
25
|
getHash: () => getHash,
|
|
24
26
|
isServerTarget: () => isServerTarget
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(utils_exports);
|
|
27
29
|
const RUNTIME_CHUNK_NAME = "builder-runtime";
|
|
30
|
+
const JS_REGEX = /\.(?:js|mjs|cjs|jsx)$/;
|
|
28
31
|
const TS_REGEX = /\.(?:ts|mts|cts|tsx)$/;
|
|
29
32
|
function isServerTarget(target) {
|
|
30
33
|
return (Array.isArray(target) ? target : [
|
|
@@ -34,6 +37,14 @@ function isServerTarget(target) {
|
|
|
34
37
|
"service-worker"
|
|
35
38
|
].includes(item));
|
|
36
39
|
}
|
|
40
|
+
const castArray = (arr) => {
|
|
41
|
+
if (arr === void 0) {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
return Array.isArray(arr) ? arr : [
|
|
45
|
+
arr
|
|
46
|
+
];
|
|
47
|
+
};
|
|
37
48
|
const getHash = (config) => {
|
|
38
49
|
const { filenameHash } = config.output;
|
|
39
50
|
if (typeof filenameHash === "string") {
|
|
@@ -43,8 +54,10 @@ const getHash = (config) => {
|
|
|
43
54
|
};
|
|
44
55
|
// Annotate the CommonJS export names for ESM import in node:
|
|
45
56
|
0 && (module.exports = {
|
|
57
|
+
JS_REGEX,
|
|
46
58
|
RUNTIME_CHUNK_NAME,
|
|
47
59
|
TS_REGEX,
|
|
60
|
+
castArray,
|
|
48
61
|
getHash,
|
|
49
62
|
isServerTarget
|
|
50
63
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { NodeEnv, MetaOptions,
|
|
2
|
-
import type { DevConfig, RsbuildConfig, RsbuildTarget, Polyfill, ScriptInject, ServerConfig, RsbuildPluginAPI, SourceConfig } from '@rsbuild/core';
|
|
1
|
+
import type { NodeEnv, MetaOptions, RequestHandler, HtmlTagDescriptor } from '@rsbuild/shared';
|
|
2
|
+
import type { ConfigChainWithContext, ConfigChain, DevConfig, RsbuildConfig, RsbuildTarget, Polyfill, ScriptInject, ServerConfig, RsbuildPluginAPI, SourceConfig, OutputConfig } 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';
|
|
@@ -193,11 +193,11 @@ export type UniBuilderExtraConfig = {
|
|
|
193
193
|
/**
|
|
194
194
|
* @deprecated use `output.inlineScripts` instead
|
|
195
195
|
*/
|
|
196
|
-
enableInlineScripts?:
|
|
196
|
+
enableInlineScripts?: OutputConfig['inlineScripts'];
|
|
197
197
|
/**
|
|
198
198
|
* @deprecated use `output.inlineStyles` instead
|
|
199
199
|
*/
|
|
200
|
-
enableInlineStyles?:
|
|
200
|
+
enableInlineStyles?: OutputConfig['injectStyles'];
|
|
201
201
|
/**
|
|
202
202
|
* Configure the default export type of SVG files.
|
|
203
203
|
*/
|
|
@@ -320,14 +320,14 @@ export type UniBuilderPluginAPI = {
|
|
|
320
320
|
getBuilderConfig: () => Readonly<any>;
|
|
321
321
|
modifyBuilderConfig: (fn: (config: any, utils: {
|
|
322
322
|
mergeBuilderConfig: <T>(...configs: T[]) => T;
|
|
323
|
-
}) =>
|
|
323
|
+
}) => any | Promise<any>) => void;
|
|
324
324
|
};
|
|
325
325
|
/**
|
|
326
326
|
* compat legacy modern.js builder plugin
|
|
327
327
|
*/
|
|
328
328
|
export type UniBuilderPlugin = {
|
|
329
329
|
name: string;
|
|
330
|
-
setup: (api: UniBuilderPluginAPI) =>
|
|
330
|
+
setup: (api: UniBuilderPluginAPI) => void | Promise<void>;
|
|
331
331
|
pre?: string[];
|
|
332
332
|
post?: string[];
|
|
333
333
|
remove?: string[];
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
import type { DevConfig } from '@rsbuild/shared';
|
|
1
|
+
import type { RsbuildPlugin, DevConfig } from '@rsbuild/core';
|
|
3
2
|
type LazyCompilationOptions = DevConfig['lazyCompilation'];
|
|
4
3
|
export declare const pluginLazyCompilation: (options: LazyCompilationOptions) => RsbuildPlugin;
|
|
5
4
|
export {};
|
|
@@ -31,7 +31,6 @@ __export(minimize_exports, {
|
|
|
31
31
|
pluginMinimize: () => pluginMinimize
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(minimize_exports);
|
|
34
|
-
var import_shared = require("@rsbuild/shared");
|
|
35
34
|
var import_utils = require("@modern-js/utils");
|
|
36
35
|
function applyRemoveConsole(options, config) {
|
|
37
36
|
const { removeConsole } = config.performance;
|
|
@@ -50,7 +49,7 @@ function applyRemoveConsole(options, config) {
|
|
|
50
49
|
}
|
|
51
50
|
return options;
|
|
52
51
|
}
|
|
53
|
-
async function applyJSMinimizer(chain, config, userTerserConfig) {
|
|
52
|
+
async function applyJSMinimizer(chain, config, CHAIN_ID, userTerserConfig) {
|
|
54
53
|
const { default: TerserPlugin } = await Promise.resolve().then(() => __toESM(require("terser-webpack-plugin")));
|
|
55
54
|
const DEFAULT_OPTIONS = {
|
|
56
55
|
terserOptions: {
|
|
@@ -78,7 +77,7 @@ async function applyJSMinimizer(chain, config, userTerserConfig) {
|
|
|
78
77
|
break;
|
|
79
78
|
}
|
|
80
79
|
const mergedOptions = (0, import_utils.applyOptionsChain)(DEFAULT_OPTIONS, userTerserConfig);
|
|
81
|
-
chain.optimization.minimizer(
|
|
80
|
+
chain.optimization.minimizer(CHAIN_ID.MINIMIZER.JS).use(TerserPlugin, [
|
|
82
81
|
// Due to terser-webpack-plugin has changed the type of class, which using a generic type in
|
|
83
82
|
// constructor, leading auto inference of parameters of plugin constructor is not possible, using any instead
|
|
84
83
|
mergedOptions
|
|
@@ -87,14 +86,14 @@ async function applyJSMinimizer(chain, config, userTerserConfig) {
|
|
|
87
86
|
const pluginMinimize = (userTerserConfig) => ({
|
|
88
87
|
name: "uni-builder:minimize",
|
|
89
88
|
setup(api) {
|
|
90
|
-
api.modifyBundlerChain(async (chain, { isProd }) => {
|
|
89
|
+
api.modifyBundlerChain(async (chain, { isProd, CHAIN_ID }) => {
|
|
91
90
|
const config = api.getNormalizedConfig();
|
|
92
91
|
const { minify } = config.output;
|
|
93
92
|
if (minify === false || !isProd) {
|
|
94
93
|
return;
|
|
95
94
|
}
|
|
96
95
|
if (minify === true || (minify === null || minify === void 0 ? void 0 : minify.js) !== false) {
|
|
97
|
-
await applyJSMinimizer(chain, config, userTerserConfig);
|
|
96
|
+
await applyJSMinimizer(chain, config, CHAIN_ID, userTerserConfig);
|
|
98
97
|
}
|
|
99
98
|
});
|
|
100
99
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
import { type ConfigChain } from '@rsbuild/shared';
|
|
1
|
+
import type { RsbuildPlugin, ConfigChain } from '@rsbuild/core';
|
|
3
2
|
import type { ModuleScopes } from '../../types';
|
|
4
3
|
export declare const isPrimitiveScope: (items: unknown[]) => items is (string | RegExp)[];
|
|
5
4
|
export declare const applyScopeChain: (defaults: ModuleScopes, options: ConfigChain<ModuleScopes>) => ModuleScopes;
|
|
@@ -31,7 +31,6 @@ __export(react_exports, {
|
|
|
31
31
|
pluginReact: () => pluginReact
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(react_exports);
|
|
34
|
-
var import_shared = require("@rsbuild/shared");
|
|
35
34
|
const pluginReact = () => ({
|
|
36
35
|
name: "uni-builder:react",
|
|
37
36
|
pre: [
|
|
@@ -40,7 +39,8 @@ const pluginReact = () => ({
|
|
|
40
39
|
setup(api) {
|
|
41
40
|
api.modifyBundlerChain(async (chain, utils) => {
|
|
42
41
|
const config = api.getNormalizedConfig();
|
|
43
|
-
|
|
42
|
+
const usingHMR = !utils.isProd && config.dev.hmr && utils.target === "web";
|
|
43
|
+
if (!usingHMR) {
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
const { CHAIN_ID } = utils;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
-
import { type ConfigChain } from '@rsbuild/shared';
|
|
1
|
+
import type { RsbuildPlugin, ConfigChain } from '@rsbuild/core';
|
|
3
2
|
import type { PluginStyledComponentsOptions } from '@rsbuild/plugin-styled-components';
|
|
4
3
|
export declare const pluginStyledComponents: (userConfig?: ConfigChain<PluginStyledComponentsOptions>) => RsbuildPlugin;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type FileFilterUtil
|
|
1
|
+
import { type FileFilterUtil } from '@rsbuild/shared';
|
|
2
|
+
import { type ConfigChainWithContext } from '@rsbuild/core';
|
|
2
3
|
import { PluginBabelOptions } from '@rsbuild/plugin-babel';
|
|
3
4
|
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
4
5
|
import type { Options as RawTSLoaderOptions } from 'ts-loader';
|
|
@@ -64,10 +64,10 @@ const pluginTsLoader = (options, babelOptions) => {
|
|
|
64
64
|
const excludes = [];
|
|
65
65
|
const tsLoaderUtils = {
|
|
66
66
|
addIncludes(items) {
|
|
67
|
-
includes.push(...(0,
|
|
67
|
+
includes.push(...(0, import_utils2.castArray)(items));
|
|
68
68
|
},
|
|
69
69
|
addExcludes(items) {
|
|
70
|
-
excludes.push(...(0,
|
|
70
|
+
excludes.push(...(0, import_utils2.castArray)(items));
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
73
|
const tsLoaderDefaultOptions = {
|
|
@@ -93,7 +93,7 @@ const pluginTsLoader = (options, babelOptions) => {
|
|
|
93
93
|
includes,
|
|
94
94
|
excludes
|
|
95
95
|
});
|
|
96
|
-
chain.module.rule(CHAIN_ID.RULE.JS).test(
|
|
96
|
+
chain.module.rule(CHAIN_ID.RULE.JS).test(import_utils2.JS_REGEX);
|
|
97
97
|
rule.test(import_utils2.TS_REGEX).use(CHAIN_ID.USE.BABEL).loader(require.resolve("babel-loader")).options({
|
|
98
98
|
...babelLoaderOptions,
|
|
99
99
|
// fix repeatedly insert babel plugin in some boundary cases
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/uni-builder",
|
|
3
|
-
"version": "0.0.0-nightly-
|
|
3
|
+
"version": "0.0.0-nightly-20240708170628",
|
|
4
4
|
"description": "Unified builder for Modern.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -69,9 +69,9 @@
|
|
|
69
69
|
"ts-loader": "9.4.4",
|
|
70
70
|
"webpack": "^5.92.0",
|
|
71
71
|
"webpack-subresource-integrity": "5.1.0",
|
|
72
|
-
"@modern-js/utils": "0.0.0-nightly-
|
|
73
|
-
"@modern-js/server": "0.0.0-nightly-
|
|
74
|
-
"@modern-js/prod-server": "0.0.0-nightly-
|
|
72
|
+
"@modern-js/utils": "0.0.0-nightly-20240708170628",
|
|
73
|
+
"@modern-js/server": "0.0.0-nightly-20240708170628",
|
|
74
|
+
"@modern-js/prod-server": "0.0.0-nightly-20240708170628"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@rsbuild/plugin-swc": "0.7.10",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"react": "^18.2.0",
|
|
80
80
|
"react-dom": "^18.2.0",
|
|
81
81
|
"typescript": "^5.3.0",
|
|
82
|
-
"@scripts/build": "0.0.0-nightly-
|
|
83
|
-
"@scripts/vitest-config": "0.0.0-nightly-
|
|
82
|
+
"@scripts/build": "0.0.0-nightly-20240708170628",
|
|
83
|
+
"@scripts/vitest-config": "0.0.0-nightly-20240708170628"
|
|
84
84
|
},
|
|
85
85
|
"publishConfig": {
|
|
86
86
|
"access": "public",
|