@lynx-js/rspeedy 0.13.6 → 0.14.1
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/CHANGELOG.md +20 -0
- package/dist/0~src_config_validate_ts.js +1485 -1427
- package/dist/0~src_plugins_minify_plugin_ts.js +92 -21
- package/dist/1~src_config_validate_ts.js +1485 -1427
- package/dist/1~src_plugins_minify_plugin_ts.js +95 -21
- package/dist/index.d.ts +275 -141
- package/dist/src_cli_main_ts.js +1 -1
- package/dist/src_index_ts.js +1 -1
- package/package.json +4 -4
|
@@ -1,29 +1,51 @@
|
|
|
1
|
-
import { debug } from "./src_cli_main_ts.js";
|
|
1
|
+
import { mergeRsbuildConfig as core_mergeRsbuildConfig, debug } from "./src_cli_main_ts.js";
|
|
2
|
+
function mergeRspeedyConfig(...configs) {
|
|
3
|
+
return core_mergeRsbuildConfig(...configs);
|
|
4
|
+
}
|
|
5
|
+
const MAIN_THREAD_JS_PATTERN = /.*main-thread(?:\.[A-Fa-f0-9]*)?\.js$/;
|
|
6
|
+
const BACKGROUND_JS_PATTERN = /.*background(?:\.[A-Fa-f0-9]*)?\.js$/;
|
|
7
|
+
function mergeJsOptions(baseOptions, threadOptions) {
|
|
8
|
+
const merged = mergeRspeedyConfig({
|
|
9
|
+
output: {
|
|
10
|
+
minify: {
|
|
11
|
+
jsOptions: baseOptions
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}, {
|
|
15
|
+
output: {
|
|
16
|
+
minify: {
|
|
17
|
+
jsOptions: threadOptions
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return merged.output?.minify?.jsOptions ?? {};
|
|
22
|
+
}
|
|
2
23
|
function pluginMinify(options) {
|
|
24
|
+
const defaultJsOptions = Object.freeze({
|
|
25
|
+
minimizerOptions: {
|
|
26
|
+
compress: {
|
|
27
|
+
negate_iife: false,
|
|
28
|
+
join_vars: false,
|
|
29
|
+
ecma: 2015,
|
|
30
|
+
inline: 2,
|
|
31
|
+
comparisons: false,
|
|
32
|
+
toplevel: true,
|
|
33
|
+
side_effects: false
|
|
34
|
+
},
|
|
35
|
+
format: {
|
|
36
|
+
keep_quoted_props: true,
|
|
37
|
+
comments: false
|
|
38
|
+
},
|
|
39
|
+
mangle: {
|
|
40
|
+
toplevel: true
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
3
44
|
const defaultConfig = Object.freeze({
|
|
4
45
|
output: {
|
|
5
46
|
minify: {
|
|
6
47
|
js: true,
|
|
7
|
-
jsOptions:
|
|
8
|
-
minimizerOptions: {
|
|
9
|
-
compress: {
|
|
10
|
-
negate_iife: false,
|
|
11
|
-
join_vars: false,
|
|
12
|
-
ecma: 2015,
|
|
13
|
-
inline: 2,
|
|
14
|
-
comparisons: false,
|
|
15
|
-
toplevel: true,
|
|
16
|
-
side_effects: false
|
|
17
|
-
},
|
|
18
|
-
format: {
|
|
19
|
-
keep_quoted_props: true,
|
|
20
|
-
comments: false
|
|
21
|
-
},
|
|
22
|
-
mangle: {
|
|
23
|
-
toplevel: true
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
},
|
|
48
|
+
jsOptions: defaultJsOptions,
|
|
27
49
|
css: true,
|
|
28
50
|
cssOptions: {
|
|
29
51
|
minimizerOptions: {
|
|
@@ -69,6 +91,58 @@ function pluginMinify(options) {
|
|
|
69
91
|
}
|
|
70
92
|
return mergeRsbuildConfig(...configs);
|
|
71
93
|
});
|
|
94
|
+
api.modifyBundlerChain((chain, { rspack, CHAIN_ID })=>{
|
|
95
|
+
const currentConfig = api.getRsbuildConfig('normalized');
|
|
96
|
+
const minify = currentConfig.output?.minify;
|
|
97
|
+
if ('object' != typeof minify || null === minify || false === minify.js) return;
|
|
98
|
+
if (void 0 === minify.mainThreadOptions && void 0 === minify.backgroundOptions) return;
|
|
99
|
+
const jsOptions = minify.jsOptions ?? {};
|
|
100
|
+
if (chain.optimization.minimizers.has(CHAIN_ID.MINIMIZER.JS)) chain.optimization.minimizer(CHAIN_ID.MINIMIZER.JS).tap((args)=>{
|
|
101
|
+
const defaultOptions = args[0] ?? {};
|
|
102
|
+
const threadExclude = [
|
|
103
|
+
MAIN_THREAD_JS_PATTERN,
|
|
104
|
+
BACKGROUND_JS_PATTERN
|
|
105
|
+
];
|
|
106
|
+
defaultOptions.exclude = defaultOptions.exclude ? Array.isArray(defaultOptions.exclude) ? [
|
|
107
|
+
...defaultOptions.exclude,
|
|
108
|
+
...threadExclude
|
|
109
|
+
] : [
|
|
110
|
+
defaultOptions.exclude,
|
|
111
|
+
...threadExclude
|
|
112
|
+
] : threadExclude;
|
|
113
|
+
return [
|
|
114
|
+
defaultOptions
|
|
115
|
+
];
|
|
116
|
+
});
|
|
117
|
+
const mainThreadOptions = mergeJsOptions(jsOptions, minify.mainThreadOptions);
|
|
118
|
+
const mtInclude = [
|
|
119
|
+
MAIN_THREAD_JS_PATTERN
|
|
120
|
+
];
|
|
121
|
+
mainThreadOptions.include = mainThreadOptions.include ? Array.isArray(mainThreadOptions.include) ? [
|
|
122
|
+
...mainThreadOptions.include,
|
|
123
|
+
...mtInclude
|
|
124
|
+
] : [
|
|
125
|
+
mainThreadOptions.include,
|
|
126
|
+
...mtInclude
|
|
127
|
+
] : mtInclude;
|
|
128
|
+
chain.optimization.minimizer('js-main-thread').use(rspack.SwcJsMinimizerRspackPlugin, [
|
|
129
|
+
mainThreadOptions
|
|
130
|
+
]).end();
|
|
131
|
+
const backgroundOptions = mergeJsOptions(jsOptions, minify.backgroundOptions);
|
|
132
|
+
const bgInclude = [
|
|
133
|
+
BACKGROUND_JS_PATTERN
|
|
134
|
+
];
|
|
135
|
+
backgroundOptions.include = backgroundOptions.include ? Array.isArray(backgroundOptions.include) ? [
|
|
136
|
+
...backgroundOptions.include,
|
|
137
|
+
...bgInclude
|
|
138
|
+
] : [
|
|
139
|
+
backgroundOptions.include,
|
|
140
|
+
...bgInclude
|
|
141
|
+
] : bgInclude;
|
|
142
|
+
chain.optimization.minimizer('js-background').use(rspack.SwcJsMinimizerRspackPlugin, [
|
|
143
|
+
backgroundOptions
|
|
144
|
+
]).end();
|
|
145
|
+
});
|
|
72
146
|
}
|
|
73
147
|
};
|
|
74
148
|
}
|