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