@lynx-js/rspeedy 0.9.4 → 0.9.5

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 CHANGED
@@ -1,5 +1,51 @@
1
1
  # @lynx-js/rspeedy
2
2
 
3
+ ## 0.9.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Support `source.preEntry`. ([#750](https://github.com/lynx-family/lynx-stack/pull/750))
8
+
9
+ Add a script before the entry file of each page. This script will be executed before the page code.
10
+ It can be used to execute global logics, such as injecting polyfills, setting global styles, etc.
11
+
12
+ example:
13
+
14
+ ```js
15
+ import { defineConfig } from '@lynx-js/rspeedy'
16
+ export default defineConfig({
17
+ source: {
18
+ preEntry: './src/polyfill.ts',
19
+ },
20
+ })
21
+ ```
22
+
23
+ - Bump Rsbuild v1.3.20 with Rspack v1.3.10. ([#799](https://github.com/lynx-family/lynx-stack/pull/799))
24
+
25
+ - Add `callerName` option to `createRspeedy`. ([#757](https://github.com/lynx-family/lynx-stack/pull/757))
26
+
27
+ It can be accessed by Rsbuild plugins through [`api.context.callerName`](https://rsbuild.dev/api/javascript-api/instance#contextcallername), and execute different logic based on this identifier.
28
+
29
+ ```js
30
+ export const myPlugin = {
31
+ name: 'my-plugin',
32
+ setup(api) {
33
+ const { callerName } = api.context
34
+
35
+ if (callerName === 'rslib') {
36
+ // ...
37
+ } else if (callerName === 'rspeedy') {
38
+ // ...
39
+ }
40
+ },
41
+ }
42
+ ```
43
+
44
+ - Support `performance.buildCache`. ([#766](https://github.com/lynx-family/lynx-stack/pull/766))
45
+
46
+ - Updated dependencies [[`fbc4fbb`](https://github.com/lynx-family/lynx-stack/commit/fbc4fbbdb572ad7128a33dc06e8d8a026d18e388)]:
47
+ - @lynx-js/webpack-dev-transport@0.1.3
48
+
3
49
  ## 0.9.4
4
50
 
5
51
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -31,6 +31,79 @@ import { rspack } from '@rsbuild/core';
31
31
  import type { ToolsConfig } from '@rsbuild/core';
32
32
  import type { WatchFiles } from '@rsbuild/core';
33
33
 
34
+ /**
35
+ * {@inheritdoc Performance.buildCache}
36
+ *
37
+ * @beta
38
+ */
39
+ export declare interface BuildCache {
40
+ /**
41
+ * Add additional cache digests, the previous build cache will be invalidated
42
+ * when any value in the array changes.
43
+ *
44
+ * @defaultValue undefined
45
+ *
46
+ * @example
47
+ *
48
+ * Add `process.env.SOME_ENV` to the cache digest.
49
+ *
50
+ * ```js
51
+ * import { defineConfig } from '@lynx-js/rspeedy'
52
+ *
53
+ * export default defineConfig({
54
+ * performance: {
55
+ * buildCache: {
56
+ * cacheDigest: [process.env.SOME_ENV],
57
+ * },
58
+ * },
59
+ * })
60
+ * ```
61
+ */
62
+ cacheDigest?: Array<string | undefined> | undefined;
63
+ /**
64
+ * The output directory of the cache files.
65
+ *
66
+ * @defaultValue 'node_modules/.cache'
67
+ */
68
+ cacheDirectory?: string | undefined;
69
+ /**
70
+ * An array of files containing build dependencies.
71
+ * Rspack will use the hash of each of these files to invalidate the persistent cache.
72
+ *
73
+ * @remarks
74
+ *
75
+ * Rspeedy will use the following configuration files as the default build dependencies:
76
+ *
77
+ * - `package.json`
78
+ *
79
+ * - `tsconfig.json` (or `source.tsconfigPath`)
80
+ *
81
+ * - `.env`, `.env.*`
82
+ *
83
+ * - `tailwindcss.config.*`
84
+ *
85
+ * When using Rspeedy CLI, it will also automatically add
86
+ * `lynx.config.js` to the build dependencies.
87
+ *
88
+ * @example
89
+ *
90
+ * Add `postcss.config.js` to the build dependencies.
91
+ *
92
+ * ```js
93
+ * import { defineConfig } from '@lynx-js/rspeedy'
94
+ *
95
+ * export default defineConfig({
96
+ * performance: {
97
+ * buildCache: {
98
+ * buildDependencies: ['postcss.config.js'],
99
+ * },
100
+ * },
101
+ * })
102
+ * ```
103
+ */
104
+ buildDependencies?: string[] | undefined;
105
+ }
106
+
34
107
  /**
35
108
  * {@inheritdoc Performance.chunkSplit}
36
109
  *
@@ -417,7 +490,7 @@ export declare type ConsoleType = 'log' | 'warn' | 'error' | 'info' | 'debug' |
417
490
  *
418
491
  * @public
419
492
  */
420
- export declare function createRspeedy({ cwd, rspeedyConfig, loadEnv, environment }: CreateRspeedyOptions): Promise<RspeedyInstance>;
493
+ export declare function createRspeedy({ cwd, rspeedyConfig, loadEnv, environment, callerName, }: CreateRspeedyOptions): Promise<RspeedyInstance>;
421
494
 
422
495
  /**
423
496
  * The options of `createRspeedy` method.
@@ -448,6 +521,42 @@ export declare interface CreateRspeedyOptions {
448
521
  * @defaultValue []
449
522
  */
450
523
  environment?: CreateRsbuildOptions['environment'];
524
+ /**
525
+ * The name of the framework or tool that is currently invoking Rsbuild.
526
+ * This allows plugins to tailor their behavior based on the calling context.
527
+ *
528
+ * @example
529
+ *
530
+ * Rsbuild plugins can access this value via `api.context.callerName`.
531
+ *
532
+ * ```js
533
+ * export function myPlugin() {
534
+ * return {
535
+ * name: 'my-plugin',
536
+ * setup(api) {
537
+ * // Log the name of the tool invoking Rsbuild
538
+ * console.log(`Called by: ${api.context.callerName}`);
539
+ *
540
+ * // Conditionally apply plugin logic based on caller
541
+ * if (api.context.callerName === 'rspeedy') {
542
+ * api.modifyRsbuildConfig((config) => {
543
+ * // Apply rspeedy-specific config changes
544
+ * return config;
545
+ * });
546
+ * } else if (api.context.callerName === 'rslib') {
547
+ * api.modifyRsbuildConfig((config) => {
548
+ * // Apply rslib-specific config changes
549
+ * return config;
550
+ * });
551
+ * }
552
+ * }
553
+ * };
554
+ * }
555
+ * ```
556
+ *
557
+ * @defaultValue 'rspeedy'
558
+ */
559
+ callerName?: string;
451
560
  }
452
561
 
453
562
  /**
@@ -1895,6 +2004,43 @@ export declare interface Output {
1895
2004
  * @public
1896
2005
  */
1897
2006
  export declare interface Performance {
2007
+ /**
2008
+ * Enable or configure persistent build cache.
2009
+ *
2010
+ * @beta This feature is experimental and may be changed in the future.
2011
+ *
2012
+ * @example
2013
+ *
2014
+ * Enable persistent build cache.
2015
+ *
2016
+ * ```js
2017
+ * import { defineConfig } from '@lynx-js/rspeedy'
2018
+ *
2019
+ * export default defineConfig({
2020
+ * performance: {
2021
+ * buildCache: true,
2022
+ * },
2023
+ * })
2024
+ * ```
2025
+ *
2026
+ * @example
2027
+ *
2028
+ * Customize build cache.
2029
+ *
2030
+ * ```js
2031
+ * import { defineConfig } from '@lynx-js/rspeedy'
2032
+ *
2033
+ * export default defineConfig({
2034
+ * performance: {
2035
+ * buildCache: {
2036
+ * cacheDigest: [process.env.SOME_ENV],
2037
+ * buildDependencies: ['postcss.config.js'],
2038
+ * },
2039
+ * },
2040
+ * })
2041
+ * ```
2042
+ */
2043
+ buildCache?: BuildCache | boolean | undefined;
1898
2044
  /**
1899
2045
  * {@link Performance.chunkSplit} is used to configure the chunk splitting strategy.
1900
2046
  */
@@ -2415,7 +2561,9 @@ export declare interface Source {
2415
2561
  * ```js
2416
2562
  * import { defineConfig } from '@lynx-js/rspeedy'
2417
2563
  * export default defineConfig({
2418
- * entry: './src/pages/main/index.js',
2564
+ * source: {
2565
+ * entry: './src/pages/main/index.js',
2566
+ * },
2419
2567
  * })
2420
2568
  * ```
2421
2569
  *
@@ -2426,7 +2574,9 @@ export declare interface Source {
2426
2574
  * ```js
2427
2575
  * import { defineConfig } from '@lynx-js/rspeedy'
2428
2576
  * export default defineConfig({
2429
- * entry: ['./src/prefetch.js', './src/pages/main/index.js'],
2577
+ * source: {
2578
+ * entry: ['./src/prefetch.js', './src/pages/main/index.js'],
2579
+ * },
2430
2580
  * })
2431
2581
  * ```
2432
2582
  *
@@ -2437,9 +2587,11 @@ export declare interface Source {
2437
2587
  * ```js
2438
2588
  * import { defineConfig } from '@lynx-js/rspeedy'
2439
2589
  * export default defineConfig({
2440
- * entry: {
2441
- * foo: './src/pages/foo/index.js',
2442
- * bar: ['./src/pages/bar/index.js', './src/post.js'], // multiple entry modules is allowed
2590
+ * source: {
2591
+ * entry: {
2592
+ * foo: './src/pages/foo/index.js',
2593
+ * bar: ['./src/pages/bar/index.js', './src/post.js'], // multiple entry modules is allowed
2594
+ * },
2443
2595
  * },
2444
2596
  * })
2445
2597
  * ```
@@ -2451,10 +2603,12 @@ export declare interface Source {
2451
2603
  * ```js
2452
2604
  * import { defineConfig } from '@lynx-js/rspeedy'
2453
2605
  * export default defineConfig({
2454
- * entry: {
2455
- * foo: './src/pages/foo/index.js',
2456
- * bar: {
2457
- * import: ['./src/prefetch.js', './src/pages/bar'],
2606
+ * source: {
2607
+ * entry: {
2608
+ * foo: './src/pages/foo/index.js',
2609
+ * bar: {
2610
+ * import: ['./src/prefetch.js', './src/pages/bar'],
2611
+ * },
2458
2612
  * },
2459
2613
  * },
2460
2614
  * })
@@ -2597,6 +2751,28 @@ export declare interface Source {
2597
2751
  * ```
2598
2752
  */
2599
2753
  include?: Rspack.RuleSetCondition[] | undefined;
2754
+ /**
2755
+ * Add a script before the entry file of each page. This script will be executed before the page code.
2756
+ * It can be used to execute global logics, such as injecting polyfills, setting global styles, etc.
2757
+ *
2758
+ * @remarks
2759
+ *
2760
+ * See {@link https://rsbuild.dev/config/source/pre-entry | source.preEntry} for more details.
2761
+ *
2762
+ * @example
2763
+ *
2764
+ * Relative path will be resolved relative to the project root directory.
2765
+ *
2766
+ * ```js
2767
+ * import { defineConfig } from '@lynx-js/rspeedy'
2768
+ * export default defineConfig({
2769
+ * source: {
2770
+ * preEntry: './src/polyfill.ts',
2771
+ * },
2772
+ * })
2773
+ * ```
2774
+ */
2775
+ preEntry?: string | string[] | undefined;
2600
2776
  /**
2601
2777
  * The {@link TransformImport} option transforms the import paths to enable modular imports from subpaths of third-party packages, similar to the functionality provided by {@link https://npmjs.com/package/babel-plugin-import | babel-plugin-import}.
2602
2778
  *
package/dist/index.js CHANGED
@@ -112,7 +112,7 @@ var __webpack_modules__ = {
112
112
  });
113
113
  var core_ = __webpack_require__("@rsbuild/core");
114
114
  var package_namespaceObject = {
115
- i8: "0.9.4"
115
+ i8: "0.9.5"
116
116
  };
117
117
  const version = package_namespaceObject.i8;
118
118
  const rspackVersion = core_.rspack.rspackVersion;
@@ -355,6 +355,7 @@ function toRsbuildConfig(config) {
355
355
  entry: toRsbuildEntry(config.source?.entry),
356
356
  exclude: config.source?.exclude,
357
357
  include: config.source?.include,
358
+ preEntry: config.source?.preEntry,
358
359
  transformImport: config.source?.transformImport,
359
360
  tsconfigPath: config.source?.tsconfigPath
360
361
  },
@@ -367,6 +368,7 @@ function toRsbuildConfig(config) {
367
368
  },
368
369
  plugins: config.plugins,
369
370
  performance: {
371
+ buildCache: config.performance?.buildCache,
370
372
  chunkSplit: config.performance?.chunkSplit,
371
373
  profile: config.performance?.profile,
372
374
  removeConsole: toRsbuildRemoveConsole(config),
@@ -394,14 +396,15 @@ function toRsbuildRemoveConsole(config) {
394
396
  ];
395
397
  return config.performance?.removeConsole;
396
398
  }
397
- async function createRspeedy({ cwd = process.cwd(), rspeedyConfig = {}, loadEnv = true, environment = [] }) {
399
+ async function createRspeedy({ cwd = process.cwd(), rspeedyConfig = {}, loadEnv = true, environment = [], callerName = 'rspeedy' }) {
398
400
  const config = applyDefaultRspeedyConfig(rspeedyConfig);
399
401
  const [rspeedy, { applyDefaultPlugins }] = await Promise.all([
400
402
  (0, core_.createRsbuild)({
401
403
  cwd,
402
404
  loadEnv,
403
405
  rsbuildConfig: toRsbuildConfig(config),
404
- environment
406
+ environment,
407
+ callerName
405
408
  }),
406
409
  __webpack_require__.e("src_plugins_index_ts").then(__webpack_require__.bind(__webpack_require__, "./src/plugins/index.ts"))
407
410
  ]);
@@ -104,6 +104,15 @@ export const __webpack_modules__ = {
104
104
  cwd,
105
105
  configPath: options.config
106
106
  });
107
+ if (rspeedyConfig.performance?.buildCache) if (true === rspeedyConfig.performance.buildCache) rspeedyConfig.performance.buildCache = {
108
+ buildDependencies: [
109
+ configPath
110
+ ]
111
+ };
112
+ else {
113
+ rspeedyConfig.performance.buildCache.buildDependencies ??= [];
114
+ rspeedyConfig.performance.buildCache.buildDependencies.push(configPath);
115
+ }
107
116
  const createRspeedyOptions = {
108
117
  cwd,
109
118
  rspeedyConfig
@@ -233,6 +242,7 @@ export const __webpack_modules__ = {
233
242
  entry: toRsbuildEntry(config.source?.entry),
234
243
  exclude: config.source?.exclude,
235
244
  include: config.source?.include,
245
+ preEntry: config.source?.preEntry,
236
246
  transformImport: config.source?.transformImport,
237
247
  tsconfigPath: config.source?.tsconfigPath
238
248
  },
@@ -245,6 +255,7 @@ export const __webpack_modules__ = {
245
255
  },
246
256
  plugins: config.plugins,
247
257
  performance: {
258
+ buildCache: config.performance?.buildCache,
248
259
  chunkSplit: config.performance?.chunkSplit,
249
260
  profile: config.performance?.profile,
250
261
  removeConsole: toRsbuildRemoveConsole(config),
@@ -272,14 +283,15 @@ export const __webpack_modules__ = {
272
283
  ];
273
284
  return config.performance?.removeConsole;
274
285
  }
275
- async function createRspeedy({ cwd = process.cwd(), rspeedyConfig = {}, loadEnv = true, environment = [] }) {
286
+ async function createRspeedy({ cwd = process.cwd(), rspeedyConfig = {}, loadEnv = true, environment = [], callerName = 'rspeedy' }) {
276
287
  const config = applyDefaultRspeedyConfig(rspeedyConfig);
277
288
  const [rspeedy, { applyDefaultPlugins }] = await Promise.all([
278
289
  (0, core_.createRsbuild)({
279
290
  cwd,
280
291
  loadEnv,
281
292
  rsbuildConfig: toRsbuildConfig(config),
282
- environment
293
+ environment,
294
+ callerName
283
295
  }),
284
296
  __webpack_require__.e("src_plugins_index_ts").then(__webpack_require__.bind(__webpack_require__, "./src/plugins/index.ts"))
285
297
  ]);
@@ -40,7 +40,7 @@ export const __webpack_modules__ = {
40
40
  });
41
41
  var core_ = __webpack_require__("@rsbuild/core");
42
42
  var package_namespaceObject = {
43
- i8: "0.9.4"
43
+ i8: "0.9.5"
44
44
  };
45
45
  const version = package_namespaceObject.i8;
46
46
  const rspackVersion = core_.rspack.rspackVersion;
@@ -147,6 +147,15 @@ export const __webpack_modules__ = {
147
147
  cwd,
148
148
  configPath: options.config
149
149
  });
150
+ if (rspeedyConfig.performance?.buildCache) if (true === rspeedyConfig.performance.buildCache) rspeedyConfig.performance.buildCache = {
151
+ buildDependencies: [
152
+ configPath
153
+ ]
154
+ };
155
+ else {
156
+ rspeedyConfig.performance.buildCache.buildDependencies ??= [];
157
+ rspeedyConfig.performance.buildCache.buildDependencies.push(configPath);
158
+ }
150
159
  const createRspeedyOptions = {
151
160
  cwd,
152
161
  rspeedyConfig
@@ -276,6 +285,7 @@ export const __webpack_modules__ = {
276
285
  entry: toRsbuildEntry(config.source?.entry),
277
286
  exclude: config.source?.exclude,
278
287
  include: config.source?.include,
288
+ preEntry: config.source?.preEntry,
279
289
  transformImport: config.source?.transformImport,
280
290
  tsconfigPath: config.source?.tsconfigPath
281
291
  },
@@ -288,6 +298,7 @@ export const __webpack_modules__ = {
288
298
  },
289
299
  plugins: config.plugins,
290
300
  performance: {
301
+ buildCache: config.performance?.buildCache,
291
302
  chunkSplit: config.performance?.chunkSplit,
292
303
  profile: config.performance?.profile,
293
304
  removeConsole: toRsbuildRemoveConsole(config),
@@ -315,14 +326,15 @@ export const __webpack_modules__ = {
315
326
  ];
316
327
  return config.performance?.removeConsole;
317
328
  }
318
- async function createRspeedy({ cwd = process.cwd(), rspeedyConfig = {}, loadEnv = true, environment = [] }) {
329
+ async function createRspeedy({ cwd = process.cwd(), rspeedyConfig = {}, loadEnv = true, environment = [], callerName = 'rspeedy' }) {
319
330
  const config = applyDefaultRspeedyConfig(rspeedyConfig);
320
331
  const [rspeedy, { applyDefaultPlugins }] = await Promise.all([
321
332
  (0, core_.createRsbuild)({
322
333
  cwd,
323
334
  loadEnv,
324
335
  rsbuildConfig: toRsbuildConfig(config),
325
- environment
336
+ environment,
337
+ callerName
326
338
  }),
327
339
  __webpack_require__.e("src_plugins_index_ts").then(__webpack_require__.bind(__webpack_require__, "./src/plugins/index.ts"))
328
340
  ]);
@@ -81,6 +81,15 @@ export const __webpack_modules__ = {
81
81
  cwd,
82
82
  configPath: options.config
83
83
  });
84
+ if (rspeedyConfig.performance?.buildCache) if (true === rspeedyConfig.performance.buildCache) rspeedyConfig.performance.buildCache = {
85
+ buildDependencies: [
86
+ configPath
87
+ ]
88
+ };
89
+ else {
90
+ rspeedyConfig.performance.buildCache.buildDependencies ??= [];
91
+ rspeedyConfig.performance.buildCache.buildDependencies.push(configPath);
92
+ }
84
93
  const createRspeedyOptions = {
85
94
  cwd,
86
95
  rspeedyConfig
@@ -236,6 +245,7 @@ export const __webpack_modules__ = {
236
245
  entry: toRsbuildEntry(config.source?.entry),
237
246
  exclude: config.source?.exclude,
238
247
  include: config.source?.include,
248
+ preEntry: config.source?.preEntry,
239
249
  transformImport: config.source?.transformImport,
240
250
  tsconfigPath: config.source?.tsconfigPath
241
251
  },
@@ -248,6 +258,7 @@ export const __webpack_modules__ = {
248
258
  },
249
259
  plugins: config.plugins,
250
260
  performance: {
261
+ buildCache: config.performance?.buildCache,
251
262
  chunkSplit: config.performance?.chunkSplit,
252
263
  profile: config.performance?.profile,
253
264
  removeConsole: toRsbuildRemoveConsole(config),
@@ -275,14 +286,15 @@ export const __webpack_modules__ = {
275
286
  ];
276
287
  return config.performance?.removeConsole;
277
288
  }
278
- async function createRspeedy({ cwd = process.cwd(), rspeedyConfig = {}, loadEnv = true, environment = [] }) {
289
+ async function createRspeedy({ cwd = process.cwd(), rspeedyConfig = {}, loadEnv = true, environment = [], callerName = 'rspeedy' }) {
279
290
  const config = applyDefaultRspeedyConfig(rspeedyConfig);
280
291
  const [rspeedy, { applyDefaultPlugins }] = await Promise.all([
281
292
  (0, core_.createRsbuild)({
282
293
  cwd,
283
294
  loadEnv,
284
295
  rsbuildConfig: toRsbuildConfig(config),
285
- environment
296
+ environment,
297
+ callerName
286
298
  }),
287
299
  __webpack_require__.e("src_plugins_index_ts").then(__webpack_require__.bind(__webpack_require__, "./src/plugins/index.ts"))
288
300
  ]);
@@ -81,6 +81,15 @@ export const __webpack_modules__ = {
81
81
  cwd,
82
82
  configPath: options.config
83
83
  });
84
+ if (rspeedyConfig.performance?.buildCache) if (true === rspeedyConfig.performance.buildCache) rspeedyConfig.performance.buildCache = {
85
+ buildDependencies: [
86
+ configPath
87
+ ]
88
+ };
89
+ else {
90
+ rspeedyConfig.performance.buildCache.buildDependencies ??= [];
91
+ rspeedyConfig.performance.buildCache.buildDependencies.push(configPath);
92
+ }
84
93
  const createRspeedyOptions = {
85
94
  cwd,
86
95
  rspeedyConfig
@@ -238,6 +247,7 @@ export const __webpack_modules__ = {
238
247
  entry: toRsbuildEntry(config.source?.entry),
239
248
  exclude: config.source?.exclude,
240
249
  include: config.source?.include,
250
+ preEntry: config.source?.preEntry,
241
251
  transformImport: config.source?.transformImport,
242
252
  tsconfigPath: config.source?.tsconfigPath
243
253
  },
@@ -250,6 +260,7 @@ export const __webpack_modules__ = {
250
260
  },
251
261
  plugins: config.plugins,
252
262
  performance: {
263
+ buildCache: config.performance?.buildCache,
253
264
  chunkSplit: config.performance?.chunkSplit,
254
265
  profile: config.performance?.profile,
255
266
  removeConsole: toRsbuildRemoveConsole(config),
@@ -277,14 +288,15 @@ export const __webpack_modules__ = {
277
288
  ];
278
289
  return config.performance?.removeConsole;
279
290
  }
280
- async function createRspeedy({ cwd = process.cwd(), rspeedyConfig = {}, loadEnv = true, environment = [] }) {
291
+ async function createRspeedy({ cwd = process.cwd(), rspeedyConfig = {}, loadEnv = true, environment = [], callerName = 'rspeedy' }) {
281
292
  const config = applyDefaultRspeedyConfig(rspeedyConfig);
282
293
  const [rspeedy, { applyDefaultPlugins }] = await Promise.all([
283
294
  (0, core_.createRsbuild)({
284
295
  cwd,
285
296
  loadEnv,
286
297
  rsbuildConfig: toRsbuildConfig(config),
287
- environment
298
+ environment,
299
+ callerName
288
300
  }),
289
301
  __webpack_require__.e("src_plugins_index_ts").then(__webpack_require__.bind(__webpack_require__, "./src/plugins/index.ts"))
290
302
  ]);