@modern-js/uni-builder 2.48.5 → 2.49.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.
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { StartDevServerOptions as RsbuildStartDevServerOptions, StartServerResult, RsbuildInstance, DevConfig, ServerConfig } from '@rsbuild/shared';
|
|
2
|
-
import type {
|
|
3
|
+
import type { ModernDevServerOptions } from '@modern-js/server';
|
|
4
|
+
import type { Server } from 'node:http';
|
|
5
|
+
import { type InitProdMiddlewares } from '@modern-js/prod-server';
|
|
3
6
|
import type { UniBuilderConfig, ToolsDevServerConfig } from '../types';
|
|
4
|
-
type ServerOptions = Partial<Omit<
|
|
5
|
-
config?: Partial<
|
|
7
|
+
type ServerOptions = Partial<Omit<ModernDevServerOptions, 'config'>> & {
|
|
8
|
+
config?: Partial<ModernDevServerOptions['config']>;
|
|
6
9
|
};
|
|
7
10
|
export declare const transformToRsbuildServerOptions: (dev: NonNullable<UniBuilderConfig['dev']>, devServer: ToolsDevServerConfig) => {
|
|
8
11
|
dev: DevConfig;
|
|
@@ -11,6 +14,7 @@ export declare const transformToRsbuildServerOptions: (dev: NonNullable<UniBuild
|
|
|
11
14
|
export type StartDevServerOptions = RsbuildStartDevServerOptions & {
|
|
12
15
|
apiOnly?: boolean;
|
|
13
16
|
serverOptions?: ServerOptions;
|
|
17
|
+
initProdMiddlewares?: InitProdMiddlewares;
|
|
14
18
|
};
|
|
15
19
|
export type UniBuilderStartServerResult = Omit<StartServerResult, 'server'> & {
|
|
16
20
|
server: Server;
|
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_prod_server = require("@modern-js/prod-server");
|
|
36
37
|
const getServerOptions = (builderConfig) => {
|
|
37
38
|
var _builderConfig_output_distPath, _builderConfig_output, _builderConfig_output1, _builderConfig_output2;
|
|
38
39
|
return {
|
|
@@ -55,7 +56,7 @@ const getServerOptions = (builderConfig) => {
|
|
|
55
56
|
};
|
|
56
57
|
const transformToRsbuildServerOptions = (dev, devServer) => {
|
|
57
58
|
var _newDevServerConfig_devMiddleware, _newDevServerConfig_before, _newDevServerConfig_after;
|
|
58
|
-
const { port, host, https, ...devConfig } = dev;
|
|
59
|
+
const { port = 8080, host, https, ...devConfig } = dev;
|
|
59
60
|
var _dev_hmr;
|
|
60
61
|
const newDevServerConfig = (0, import_shared.mergeChainedOptions)({
|
|
61
62
|
defaults: {
|
|
@@ -65,7 +66,8 @@ const transformToRsbuildServerOptions = (dev, devServer) => {
|
|
|
65
66
|
hot: (_dev_hmr = dev === null || dev === void 0 ? void 0 : dev.hmr) !== null && _dev_hmr !== void 0 ? _dev_hmr : true,
|
|
66
67
|
liveReload: true,
|
|
67
68
|
client: {
|
|
68
|
-
path: "/webpack-hmr"
|
|
69
|
+
path: "/webpack-hmr",
|
|
70
|
+
overlay: false
|
|
69
71
|
}
|
|
70
72
|
},
|
|
71
73
|
options: devServer,
|
|
@@ -122,7 +124,11 @@ const getDevServerOptions = async ({ builderConfig, serverOptions }) => {
|
|
|
122
124
|
};
|
|
123
125
|
async function startDevServer(rsbuild, options = {}, builderConfig) {
|
|
124
126
|
var _serverOptions_dev, _serverOptions_dev1;
|
|
125
|
-
|
|
127
|
+
(0, import_shared.debug)("create dev server");
|
|
128
|
+
if (!options.initProdMiddlewares) {
|
|
129
|
+
options.initProdMiddlewares = import_prod_server.initProdMiddlewares;
|
|
130
|
+
}
|
|
131
|
+
const { createDevServer } = await Promise.resolve().then(() => __toESM(require("@modern-js/server")));
|
|
126
132
|
const rsbuildServer = await rsbuild.createDevServer({
|
|
127
133
|
...options,
|
|
128
134
|
runCompile: !options.apiOnly
|
|
@@ -138,9 +144,10 @@ async function startDevServer(rsbuild, options = {}, builderConfig) {
|
|
|
138
144
|
const { port } = rsbuildServer;
|
|
139
145
|
const { server: { host }, dev: { writeToDisk } } = rsbuildConfig;
|
|
140
146
|
var _serverOptions_dev_watch;
|
|
141
|
-
const server =
|
|
147
|
+
const server = await createDevServer({
|
|
142
148
|
pwd: rsbuild.context.rootPath,
|
|
143
149
|
...serverOptions,
|
|
150
|
+
appContext: serverOptions.appContext || {},
|
|
144
151
|
rsbuild,
|
|
145
152
|
getMiddlewares: () => ({
|
|
146
153
|
middlewares: rsbuildServer.middlewares,
|
|
@@ -153,7 +160,7 @@ async function startDevServer(rsbuild, options = {}, builderConfig) {
|
|
|
153
160
|
writeToDisk
|
|
154
161
|
},
|
|
155
162
|
config
|
|
156
|
-
});
|
|
163
|
+
}, options.initProdMiddlewares);
|
|
157
164
|
const protocol = https ? "https" : "http";
|
|
158
165
|
const urls = (0, import_shared.getAddressUrls)({
|
|
159
166
|
protocol,
|
|
@@ -161,7 +168,6 @@ async function startDevServer(rsbuild, options = {}, builderConfig) {
|
|
|
161
168
|
host
|
|
162
169
|
});
|
|
163
170
|
(0, import_shared.debug)("listen dev server");
|
|
164
|
-
await server.init();
|
|
165
171
|
return new Promise((resolve) => {
|
|
166
172
|
server.listen({
|
|
167
173
|
host,
|
|
@@ -108,10 +108,13 @@ async function parseCommonConfig(uniBuilderConfig, options) {
|
|
|
108
108
|
var _uniBuilderConfig_output, _uniBuilderConfig_tools;
|
|
109
109
|
var _output, _output_distPath, _output_distPath1, _output1, _extraConfig, _html, _extraConfig1;
|
|
110
110
|
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, disableSourceMap, convertToRem, disableMinimize, ...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;
|
|
111
|
+
const { plugins: [...plugins] = [], performance: { ...performanceConfig } = {}, output: { disableFilenameHash, enableLatestDecorators, cssModuleLocalIdentName, enableInlineScripts, disableCssExtract, enableInlineStyles, disableCssModuleExtension, disableTsChecker, disableSvgr, svgDefaultExport, assetsRetry, enableAssetFallback, 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;
|
|
112
112
|
const rsbuildConfig = {
|
|
113
113
|
plugins,
|
|
114
|
-
output:
|
|
114
|
+
output: {
|
|
115
|
+
polyfill: polyfill === "ua" ? "off" : polyfill,
|
|
116
|
+
...outputConfig
|
|
117
|
+
},
|
|
115
118
|
source: {
|
|
116
119
|
alias,
|
|
117
120
|
...sourceConfig
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NodeEnv, MetaOptions, ServerConfig, ScriptInject, RsbuildTarget, ChainedConfig, ChainedConfigWithUtils, InlineChunkTest, DevConfig, RequestHandler, RsbuildEntry,
|
|
1
|
+
import type { NodeEnv, MetaOptions, ServerConfig, ScriptInject, RsbuildTarget, ChainedConfig, ChainedConfigWithUtils, InlineChunkTest, DevConfig, RequestHandler, RsbuildEntry, MaybePromise, RsbuildPluginAPI, ArrayOrNot, HtmlTagDescriptor, Polyfill } from '@rsbuild/shared';
|
|
2
2
|
import type { RsbuildConfig } from '@rsbuild/core';
|
|
3
3
|
import type { PluginAssetsRetryOptions } from '@rsbuild/plugin-assets-retry';
|
|
4
4
|
import type { PluginStyledComponentsOptions } from '@rsbuild/plugin-styled-components';
|
|
@@ -309,14 +309,14 @@ export type UniBuilderPluginAPI = {
|
|
|
309
309
|
getBuilderConfig: () => Readonly<any>;
|
|
310
310
|
modifyBuilderConfig: (fn: (config: any, utils: {
|
|
311
311
|
mergeBuilderConfig: <T>(...configs: T[]) => T;
|
|
312
|
-
}) =>
|
|
312
|
+
}) => MaybePromise<any | void>) => void;
|
|
313
313
|
};
|
|
314
314
|
/**
|
|
315
315
|
* compat legacy modern.js builder plugin
|
|
316
316
|
*/
|
|
317
317
|
export type UniBuilderPlugin = {
|
|
318
318
|
name: string;
|
|
319
|
-
setup: (api: UniBuilderPluginAPI) =>
|
|
319
|
+
setup: (api: UniBuilderPluginAPI) => MaybePromise<void>;
|
|
320
320
|
pre?: string[];
|
|
321
321
|
post?: string[];
|
|
322
322
|
remove?: string[];
|
|
@@ -324,7 +324,9 @@ export type UniBuilderPlugin = {
|
|
|
324
324
|
export type UniBuilderConfig = {
|
|
325
325
|
dev?: RsbuildConfig['dev'];
|
|
326
326
|
html?: RsbuildConfig['html'];
|
|
327
|
-
output?: RsbuildConfig['output']
|
|
327
|
+
output?: Omit<NonNullable<RsbuildConfig['output']>, 'polyfill'> & {
|
|
328
|
+
polyfill?: Polyfill | 'ua';
|
|
329
|
+
};
|
|
328
330
|
performance?: RsbuildConfig['performance'];
|
|
329
331
|
security?: RsbuildConfig['security'];
|
|
330
332
|
tools?: RsbuildConfig['tools'];
|
package/dist/webpack/index.js
CHANGED
|
@@ -89,7 +89,7 @@ async function createWebpackBuilder(options) {
|
|
|
89
89
|
cwd
|
|
90
90
|
});
|
|
91
91
|
const { webpackProvider } = await Promise.resolve().then(() => __toESM(require("@rsbuild/webpack")));
|
|
92
|
-
const { setHTMLPlugin } = await Promise.resolve().then(() => __toESM(require("@rsbuild/core/
|
|
92
|
+
const { setHTMLPlugin } = await Promise.resolve().then(() => __toESM(require("@rsbuild/core/internal")));
|
|
93
93
|
const { default: HtmlWebpackPlugin } = await Promise.resolve().then(() => __toESM(require("html-webpack-plugin")));
|
|
94
94
|
setHTMLPlugin(HtmlWebpackPlugin);
|
|
95
95
|
rsbuildConfig.provider = webpackProvider;
|
|
@@ -32,11 +32,36 @@ __export(minimize_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(minimize_exports);
|
|
34
34
|
var import_shared = require("@rsbuild/shared");
|
|
35
|
+
function applyRemoveConsole(options, config) {
|
|
36
|
+
const { removeConsole } = config.performance;
|
|
37
|
+
const compressOptions = typeof options.terserOptions.compress === "boolean" ? {} : options.terserOptions.compress || {};
|
|
38
|
+
if (removeConsole === true) {
|
|
39
|
+
options.terserOptions.compress = {
|
|
40
|
+
...compressOptions,
|
|
41
|
+
drop_console: true
|
|
42
|
+
};
|
|
43
|
+
} else if (Array.isArray(removeConsole)) {
|
|
44
|
+
const pureFuncs = removeConsole.map((method) => `console.${method}`);
|
|
45
|
+
options.terserOptions.compress = {
|
|
46
|
+
...compressOptions,
|
|
47
|
+
pure_funcs: pureFuncs
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return options;
|
|
51
|
+
}
|
|
35
52
|
async function applyJSMinimizer(chain, config, userTerserConfig) {
|
|
36
53
|
const { default: TerserPlugin } = await Promise.resolve().then(() => __toESM(require("terser-webpack-plugin")));
|
|
37
54
|
const DEFAULT_OPTIONS = {
|
|
38
|
-
terserOptions:
|
|
55
|
+
terserOptions: {
|
|
56
|
+
mangle: {
|
|
57
|
+
safari10: true
|
|
58
|
+
},
|
|
59
|
+
format: {
|
|
60
|
+
ascii_only: config.output.charset === "ascii"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
39
63
|
};
|
|
64
|
+
applyRemoveConsole(DEFAULT_OPTIONS, config);
|
|
40
65
|
switch (config.output.legalComments) {
|
|
41
66
|
case "inline":
|
|
42
67
|
DEFAULT_OPTIONS.extractComments = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/uni-builder",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.49.0",
|
|
4
4
|
"description": "Unified builder for Modern.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,23 +26,23 @@
|
|
|
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-assets-retry": "0.
|
|
32
|
-
"@rsbuild/plugin-babel": "0.
|
|
33
|
-
"@rsbuild/plugin-check-syntax": "0.
|
|
34
|
-
"@rsbuild/plugin-css-minimizer": "0.
|
|
35
|
-
"@rsbuild/plugin-pug": "0.
|
|
36
|
-
"@rsbuild/plugin-react": "0.
|
|
37
|
-
"@rsbuild/plugin-rem": "0.
|
|
38
|
-
"@rsbuild/plugin-source-build": "0.
|
|
39
|
-
"@rsbuild/plugin-styled-components": "0.
|
|
40
|
-
"@rsbuild/plugin-svgr": "0.
|
|
41
|
-
"@rsbuild/plugin-type-check": "0.
|
|
42
|
-
"@rsbuild/plugin-toml": "0.
|
|
43
|
-
"@rsbuild/plugin-yaml": "0.
|
|
44
|
-
"@rsbuild/shared": "0.
|
|
45
|
-
"@rsbuild/webpack": "0.
|
|
29
|
+
"@rsbuild/babel-preset": "0.6.3",
|
|
30
|
+
"@rsbuild/core": "0.6.3",
|
|
31
|
+
"@rsbuild/plugin-assets-retry": "0.6.3",
|
|
32
|
+
"@rsbuild/plugin-babel": "0.6.3",
|
|
33
|
+
"@rsbuild/plugin-check-syntax": "0.6.3",
|
|
34
|
+
"@rsbuild/plugin-css-minimizer": "0.6.3",
|
|
35
|
+
"@rsbuild/plugin-pug": "0.6.3",
|
|
36
|
+
"@rsbuild/plugin-react": "0.6.3",
|
|
37
|
+
"@rsbuild/plugin-rem": "0.6.3",
|
|
38
|
+
"@rsbuild/plugin-source-build": "0.6.3",
|
|
39
|
+
"@rsbuild/plugin-styled-components": "0.6.3",
|
|
40
|
+
"@rsbuild/plugin-svgr": "0.6.3",
|
|
41
|
+
"@rsbuild/plugin-type-check": "0.6.3",
|
|
42
|
+
"@rsbuild/plugin-toml": "0.6.3",
|
|
43
|
+
"@rsbuild/plugin-yaml": "0.6.3",
|
|
44
|
+
"@rsbuild/shared": "0.6.3",
|
|
45
|
+
"@rsbuild/webpack": "0.6.3",
|
|
46
46
|
"@swc/helpers": "0.5.3",
|
|
47
47
|
"babel-loader": "9.1.3",
|
|
48
48
|
"babel-plugin-import": "1.13.5",
|
|
@@ -67,18 +67,18 @@
|
|
|
67
67
|
"webpack": "^5.91.0",
|
|
68
68
|
"webpack-manifest-plugin": "5.0.0",
|
|
69
69
|
"webpack-subresource-integrity": "5.1.0",
|
|
70
|
-
"@modern-js/
|
|
71
|
-
"@modern-js/
|
|
70
|
+
"@modern-js/utils": "2.49.0",
|
|
71
|
+
"@modern-js/server": "2.49.0"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@rsbuild/plugin-swc": "0.
|
|
74
|
+
"@rsbuild/plugin-swc": "0.6.3",
|
|
75
75
|
"@types/lodash": "^4.14.202",
|
|
76
76
|
"react": "^18.2.0",
|
|
77
77
|
"react-dom": "^18.2.0",
|
|
78
78
|
"typescript": "^5.3.0",
|
|
79
|
-
"@
|
|
80
|
-
"@
|
|
81
|
-
"@scripts/
|
|
79
|
+
"@scripts/vitest-config": "2.49.0",
|
|
80
|
+
"@modern-js/prod-server": "2.49.0",
|
|
81
|
+
"@scripts/build": "2.49.0"
|
|
82
82
|
},
|
|
83
83
|
"publishConfig": {
|
|
84
84
|
"access": "public",
|