@lynx-js/rspeedy 0.11.0 → 0.11.2

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,91 @@
1
1
  # @lynx-js/rspeedy
2
2
 
3
+ ## 0.11.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Support `server.proxy`. ([#1745](https://github.com/lynx-family/lynx-stack/pull/1745))
8
+
9
+ - Support `command` and `env` parameters in the function exported by `lynx.config.js`. ([#1669](https://github.com/lynx-family/lynx-stack/pull/1669))
10
+
11
+ ```js
12
+ import { defineConfig } from '@lynx-js/rspeedy'
13
+
14
+ export default defineConfig(({ command, env }) => {
15
+ const isBuild = command === 'build'
16
+ const isTest = env === 'test'
17
+
18
+ return {
19
+ output: {
20
+ minify: !isTest,
21
+ },
22
+ performance: {
23
+ buildCache: isBuild,
24
+ },
25
+ }
26
+ })
27
+ ```
28
+
29
+ - Support `resolve.dedupe`. ([#1671](https://github.com/lynx-family/lynx-stack/pull/1671))
30
+
31
+ This is useful when having multiple duplicated packages in the bundle:
32
+
33
+ ```js
34
+ import { defineConfig } from '@lynx-js/rspeedy'
35
+
36
+ export default defineConfig({
37
+ resolve: {
38
+ dedupe: ['tslib'],
39
+ },
40
+ })
41
+ ```
42
+
43
+ - Support `resolve.aliasStrategy` for controlling priority between `tsconfig.json` paths and `resolve.alias` ([#1722](https://github.com/lynx-family/lynx-stack/pull/1722))
44
+
45
+ ```js
46
+ import { defineConfig } from '@lynx-js/rspeedy'
47
+
48
+ export default defineConfig({
49
+ resolve: {
50
+ alias: {
51
+ '@': './src',
52
+ },
53
+ // 'prefer-tsconfig' (default): tsconfig.json paths take priority
54
+ // 'prefer-alias': resolve.alias takes priority
55
+ aliasStrategy: 'prefer-alias',
56
+ },
57
+ })
58
+ ```
59
+
60
+ - Bump Rsbuild v1.5.4 with Rspack v1.5.2. ([#1644](https://github.com/lynx-family/lynx-stack/pull/1644))
61
+
62
+ - Updated dependencies [[`d7c5da3`](https://github.com/lynx-family/lynx-stack/commit/d7c5da329caddfb12ed77159fb8b1b8f38717cff)]:
63
+ - @lynx-js/chunk-loading-webpack-plugin@0.3.3
64
+ - @lynx-js/cache-events-webpack-plugin@0.0.2
65
+
66
+ ## 0.11.1
67
+
68
+ ### Patch Changes
69
+
70
+ - Disable lazyCompilation by default. ([#1647](https://github.com/lynx-family/lynx-stack/pull/1647))
71
+
72
+ - Bump Rsbuild v1.5.2 with Rspack v1.5.1. ([#1624](https://github.com/lynx-family/lynx-stack/pull/1624))
73
+
74
+ - Add `output.dataUriLimit.*` for fine-grained control of asset inlining. ([#1648](https://github.com/lynx-family/lynx-stack/pull/1648))
75
+
76
+ ```js
77
+ import { defineConfig } from '@lynx-js/rspeedy'
78
+
79
+ export default defineConfig({
80
+ output: {
81
+ dataUriLimit: {
82
+ image: 5000,
83
+ media: 0,
84
+ },
85
+ },
86
+ })
87
+ ```
88
+
3
89
  ## 0.11.0
4
90
 
5
91
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -16,10 +16,12 @@
16
16
  */
17
17
 
18
18
  import type { CreateRsbuildOptions } from '@rsbuild/core';
19
+ import type { DataUriLimit } from '@rsbuild/core';
19
20
  import type { DistPathConfig } from '@rsbuild/core';
20
21
  import type { InlineChunkConfig } from '@rsbuild/core';
21
22
  import { logger } from '@rsbuild/core';
22
23
  import type { PerformanceConfig } from '@rsbuild/core';
24
+ import type { ProxyConfig } from '@rsbuild/core';
23
25
  import type { RsbuildConfig } from '@rsbuild/core';
24
26
  import type { RsbuildInstance } from '@rsbuild/core';
25
27
  import { RsbuildPlugin } from '@rsbuild/core';
@@ -442,6 +444,42 @@ export declare interface Config {
442
444
  plugins?: RsbuildPlugins | undefined;
443
445
  }
444
446
 
447
+ /**
448
+ * Parameters for the function exported from `lynx.config.js`.
449
+ *
450
+ * @public
451
+ */
452
+ export declare interface ConfigParams {
453
+ /**
454
+ * The value of `process.env['NODE_ENV']`
455
+ *
456
+ * @remarks
457
+ * Common values include (non-exhaustive):
458
+ * - `'production'`
459
+ *
460
+ * - `'development'`
461
+ *
462
+ * - `'test'`
463
+ */
464
+ env: 'production' | 'development' | 'test' | (string & Record<never, never>);
465
+ /**
466
+ * The CLI command of Rspeedy.
467
+ *
468
+ * @remarks
469
+ *
470
+ * Possible values:
471
+ *
472
+ * - `'build'`
473
+ *
474
+ * - `'dev'`
475
+ *
476
+ * - `'inspect'`
477
+ *
478
+ * - `'preview'`
479
+ */
480
+ command: 'build' | 'dev' | 'inspect' | 'preview' | (string & Record<never, never>);
481
+ }
482
+
445
483
  /**
446
484
  * The type of the console method.
447
485
  *
@@ -913,9 +951,26 @@ export declare function defineConfig(config: Config): Config;
913
951
  * })
914
952
  * ```
915
953
  *
954
+ * @example
955
+ *
956
+ * Use `defineConfig` with parameters in `lynx.config.ts`:
957
+ *
958
+ * ```ts
959
+ * import { defineConfig } from '@lynx-js/rspeedy'
960
+ *
961
+ * export default defineConfig(({ env }) => {
962
+ * const isTest = env === 'test'
963
+ * return {
964
+ * output: {
965
+ * minify: isTest ? false : true,
966
+ * },
967
+ * }
968
+ * })
969
+ * ```
970
+ *
916
971
  * @public
917
972
  */
918
- export declare function defineConfig(config: () => Config): () => Config;
973
+ export declare function defineConfig(config: (params: ConfigParams) => Config): (params: ConfigParams) => Config;
919
974
 
920
975
  /**
921
976
  * The `defineConfig` method is a helper function used to get TypeScript intellisense.
@@ -961,9 +1016,27 @@ export declare function defineConfig(config: Promise<Config>): Promise<Config>;
961
1016
  * })
962
1017
  * ```
963
1018
  *
1019
+ * @example
1020
+ *
1021
+ * Use `defineConfig` with parameters in `lynx.config.ts`:
1022
+ *
1023
+ * ```ts
1024
+ * import { defineConfig } from '@lynx-js/rspeedy'
1025
+ *
1026
+ * export default defineConfig(async ({ env }) => {
1027
+ * const foo = await bar()
1028
+ * const isTest = env === 'test'
1029
+ * return {
1030
+ * output: {
1031
+ * minify: isTest ? false : true,
1032
+ * },
1033
+ * }
1034
+ * })
1035
+ * ```
1036
+ *
964
1037
  * @public
965
1038
  */
966
- export declare function defineConfig(config: () => Promise<Config>): () => Promise<Config>;
1039
+ export declare function defineConfig(config: (params: ConfigParams) => Promise<Config>): (params: ConfigParams) => Promise<Config>;
967
1040
 
968
1041
  /**
969
1042
  * {@inheritdoc Config.dev}
@@ -1988,8 +2061,25 @@ export declare interface Output {
1988
2061
  * },
1989
2062
  * })
1990
2063
  * ```
2064
+ *
2065
+ * @example
2066
+ *
2067
+ * Disable inlining of all media but not images.
2068
+ *
2069
+ * ```ts title="lynx.config.ts"
2070
+ * import { defineConfig } from '@lynx-js/rspeedy'
2071
+ *
2072
+ * export default defineConfig({
2073
+ * output: {
2074
+ * dataUriLimit: {
2075
+ * image: 5000,
2076
+ * media: 0,
2077
+ * },
2078
+ * },
2079
+ * })
2080
+ * ```
1991
2081
  */
1992
- dataUriLimit?: number | undefined;
2082
+ dataUriLimit?: number | DataUriLimit | undefined;
1993
2083
  /**
1994
2084
  * Set the directory of the dist files.
1995
2085
  *
@@ -2452,6 +2542,54 @@ export declare interface Resolve {
2452
2542
  * ```
2453
2543
  */
2454
2544
  alias?: Record<string, string | false | string[]> | undefined;
2545
+ /**
2546
+ * Set the strategy for path alias resolution, to control the priority relationship
2547
+ * between the `paths` option in `tsconfig.json` and the `resolve.alias` option of Rsbuild.
2548
+ * - `prefer-tsconfig` (default): The `paths` option in `tsconfig.json` will take precedence over the
2549
+ * `resolve.alias` option of Rsbuild.
2550
+ * - `prefer-alias`: The `resolve.alias` option of Rsbuild will take precedence over the
2551
+ * `paths` option in `tsconfig.json`.
2552
+ *
2553
+ * @example
2554
+ *
2555
+ * ```js
2556
+ * import { defineConfig } from '@lynx-js/rspeedy'
2557
+ *
2558
+ * export default defineConfig({
2559
+ * resolve: {
2560
+ * alias: {
2561
+ * '@': './src',
2562
+ * },
2563
+ * aliasStrategy: 'prefer-alias',
2564
+ * },
2565
+ * })
2566
+ * ```
2567
+ */
2568
+ aliasStrategy?: 'prefer-tsconfig' | 'prefer-alias' | undefined;
2569
+ /**
2570
+ * Force to resolve the specified packages from project root, which is useful for deduplicating packages and reducing the bundle size.
2571
+ *
2572
+ * @remarks
2573
+ *
2574
+ * {@link Resolve.dedupe} is implemented based on {@link Resolve.alias}, it will get the path of the specified package through `require.resolve` in the project root directory and set it to the alias.
2575
+ *
2576
+ * The alias generated by {@link Resolve.dedupe} will be merged with the configured {@link Resolve.alias} in the project, and the {@link Resolve.alias} config will take precedence when the keys are the same.
2577
+ *
2578
+ * @example
2579
+ *
2580
+ * Use `tslib` from the project root directory.
2581
+ *
2582
+ * ```js
2583
+ * import { defineConfig } from '@lynx-js/rspeedy'
2584
+ *
2585
+ * export default defineConfig({
2586
+ * resolve: {
2587
+ * dedupe: ['tslib'],
2588
+ * },
2589
+ * })
2590
+ * ```
2591
+ */
2592
+ dedupe?: string[] | undefined;
2455
2593
  }
2456
2594
 
2457
2595
  export { RsbuildPlugin }
@@ -2561,6 +2699,24 @@ export declare interface Server {
2561
2699
  * ```
2562
2700
  */
2563
2701
  port?: number | undefined;
2702
+ /**
2703
+ * Configure proxy rules for the dev server or preview server to proxy requests to the specified service.
2704
+ *
2705
+ * @example
2706
+ *
2707
+ * ```js
2708
+ * export default {
2709
+ * server: {
2710
+ * proxy: {
2711
+ * // http://localhost:3000/api -> http://localhost:3000/api
2712
+ * // http://localhost:3000/api/foo -> http://localhost:3000/api/foo
2713
+ * '/api': 'http://localhost:3000',
2714
+ * },
2715
+ * },
2716
+ * }
2717
+ * ```
2718
+ */
2719
+ proxy?: ProxyConfig | undefined;
2564
2720
  /**
2565
2721
  * When a port is occupied, Rspeedy will automatically increment the port number until an available port is found.
2566
2722
  *
@@ -2978,7 +3134,7 @@ export declare interface Source {
2978
3134
  *
2979
3135
  * - The `paths` field is used to configure {@link Source.alias | Path Aliases}.
2980
3136
  *
2981
- * - Sets the scope and rules for the {@link https://rsbuild.dev/plugins/list/plugin-type-check | Type Check Plugin}.
3137
+ * - Sets the scope and rules for the {@link https://rsbuild.rs/guide/basic/typescript#type-checking | Type Check Plugin}.
2982
3138
  *
2983
3139
  * @example
2984
3140
  *
package/dist/index.js CHANGED
@@ -108,7 +108,7 @@ var __webpack_modules__ = {
108
108
  });
109
109
  var core_ = __webpack_require__("@rsbuild/core");
110
110
  var package_namespaceObject = {
111
- rE: "0.11.0"
111
+ rE: "0.11.2"
112
112
  };
113
113
  const version = package_namespaceObject.rE;
114
114
  const rspackVersion = core_.rspack.rspackVersion;
@@ -318,6 +318,7 @@ const defaultDataUriLimit = 2048;
318
318
  function toRsbuildConfig(config) {
319
319
  return {
320
320
  dev: {
321
+ lazyCompilation: false,
321
322
  watchFiles: config.dev?.watchFiles,
322
323
  writeToDisk: config.dev?.writeToDisk ?? true,
323
324
  progressBar: config.dev?.progressBar ?? true
@@ -341,7 +342,9 @@ function toRsbuildConfig(config) {
341
342
  sourceMap: config.output?.sourceMap
342
343
  },
343
344
  resolve: {
344
- alias: config.resolve?.alias
345
+ alias: config.resolve?.alias,
346
+ aliasStrategy: config.resolve?.aliasStrategy,
347
+ dedupe: config.resolve?.dedupe
345
348
  },
346
349
  source: {
347
350
  alias: config.source?.alias,
@@ -360,6 +363,7 @@ function toRsbuildConfig(config) {
360
363
  headers: config.server?.headers,
361
364
  host: config.server?.host,
362
365
  port: config.server?.port,
366
+ proxy: config.server?.proxy,
363
367
  strictPort: config.server?.strictPort
364
368
  },
365
369
  plugins: config.plugins,
@@ -467,10 +471,14 @@ async function loadConfig(loadConfigOptions) {
467
471
  import(`${specifier}?t=${Date.now()}`),
468
472
  __webpack_require__.e("src_config_validate_ts").then(__webpack_require__.bind(__webpack_require__, "./src/config/validate.ts"))
469
473
  ]);
470
- const content = validate('default' in exports ? exports.default : exports, configPath);
474
+ const configExport = 'default' in exports ? exports.default : exports;
475
+ const rawContent = 'function' == typeof configExport ? await configExport({
476
+ command: process.argv[2] ?? 'build',
477
+ env: process.env['NODE_ENV'] ?? 'production'
478
+ }) : await configExport;
471
479
  return {
472
480
  configPath,
473
- content: 'function' == typeof content ? await content() : await content
481
+ content: validate(rawContent, configPath)
474
482
  };
475
483
  } finally{
476
484
  unregister();
@@ -99,10 +99,14 @@ export const __webpack_modules__ = {
99
99
  import(`${specifier}?t=${Date.now()}`),
100
100
  __webpack_require__.e("src_config_validate_ts").then(__webpack_require__.bind(__webpack_require__, "./src/config/validate.ts"))
101
101
  ]);
102
- const content = validate('default' in exports ? exports.default : exports, configPath);
102
+ const configExport = 'default' in exports ? exports.default : exports;
103
+ const rawContent = 'function' == typeof configExport ? await configExport({
104
+ command: process.argv[2] ?? 'build',
105
+ env: process.env['NODE_ENV'] ?? 'production'
106
+ }) : await configExport;
103
107
  return {
104
108
  configPath,
105
- content: 'function' == typeof content ? await content() : await content
109
+ content: validate(rawContent, configPath)
106
110
  };
107
111
  } finally{
108
112
  unregister();
@@ -298,6 +302,7 @@ export const __webpack_modules__ = {
298
302
  function toRsbuildConfig(config) {
299
303
  return {
300
304
  dev: {
305
+ lazyCompilation: false,
301
306
  watchFiles: config.dev?.watchFiles,
302
307
  writeToDisk: config.dev?.writeToDisk ?? true,
303
308
  progressBar: config.dev?.progressBar ?? true
@@ -321,7 +326,9 @@ export const __webpack_modules__ = {
321
326
  sourceMap: config.output?.sourceMap
322
327
  },
323
328
  resolve: {
324
- alias: config.resolve?.alias
329
+ alias: config.resolve?.alias,
330
+ aliasStrategy: config.resolve?.aliasStrategy,
331
+ dedupe: config.resolve?.dedupe
325
332
  },
326
333
  source: {
327
334
  alias: config.source?.alias,
@@ -340,6 +347,7 @@ export const __webpack_modules__ = {
340
347
  headers: config.server?.headers,
341
348
  host: config.server?.host,
342
349
  port: config.server?.port,
350
+ proxy: config.server?.proxy,
343
351
  strictPort: config.server?.strictPort
344
352
  },
345
353
  plugins: config.plugins,
@@ -41,7 +41,7 @@ export const __webpack_modules__ = {
41
41
  });
42
42
  var core_ = __webpack_require__("@rsbuild/core");
43
43
  var package_namespaceObject = {
44
- rE: "0.11.0"
44
+ rE: "0.11.2"
45
45
  };
46
46
  const version = package_namespaceObject.rE;
47
47
  const rspackVersion = core_.rspack.rspackVersion;
@@ -91,10 +91,14 @@ export const __webpack_modules__ = {
91
91
  import(`${specifier}?t=${Date.now()}`),
92
92
  __webpack_require__.e("src_config_validate_ts").then(__webpack_require__.bind(__webpack_require__, "./src/config/validate.ts"))
93
93
  ]);
94
- const content = validate('default' in exports ? exports.default : exports, configPath);
94
+ const configExport = 'default' in exports ? exports.default : exports;
95
+ const rawContent = 'function' == typeof configExport ? await configExport({
96
+ command: process.argv[2] ?? 'build',
97
+ env: process.env['NODE_ENV'] ?? 'production'
98
+ }) : await configExport;
95
99
  return {
96
100
  configPath,
97
- content: 'function' == typeof content ? await content() : await content
101
+ content: validate(rawContent, configPath)
98
102
  };
99
103
  } finally{
100
104
  unregister();
@@ -290,6 +294,7 @@ export const __webpack_modules__ = {
290
294
  function toRsbuildConfig(config) {
291
295
  return {
292
296
  dev: {
297
+ lazyCompilation: false,
293
298
  watchFiles: config.dev?.watchFiles,
294
299
  writeToDisk: config.dev?.writeToDisk ?? true,
295
300
  progressBar: config.dev?.progressBar ?? true
@@ -313,7 +318,9 @@ export const __webpack_modules__ = {
313
318
  sourceMap: config.output?.sourceMap
314
319
  },
315
320
  resolve: {
316
- alias: config.resolve?.alias
321
+ alias: config.resolve?.alias,
322
+ aliasStrategy: config.resolve?.aliasStrategy,
323
+ dedupe: config.resolve?.dedupe
317
324
  },
318
325
  source: {
319
326
  alias: config.source?.alias,
@@ -332,6 +339,7 @@ export const __webpack_modules__ = {
332
339
  headers: config.server?.headers,
333
340
  host: config.server?.host,
334
341
  port: config.server?.port,
342
+ proxy: config.server?.proxy,
335
343
  strictPort: config.server?.strictPort
336
344
  },
337
345
  plugins: config.plugins,
@@ -56,10 +56,14 @@ export const __webpack_modules__ = {
56
56
  import(`${specifier}?t=${Date.now()}`),
57
57
  __webpack_require__.e("src_config_validate_ts").then(__webpack_require__.bind(__webpack_require__, "./src/config/validate.ts"))
58
58
  ]);
59
- const content = validate('default' in exports ? exports.default : exports, configPath);
59
+ const configExport = 'default' in exports ? exports.default : exports;
60
+ const rawContent = 'function' == typeof configExport ? await configExport({
61
+ command: process.argv[2] ?? 'build',
62
+ env: process.env['NODE_ENV'] ?? 'production'
63
+ }) : await configExport;
60
64
  return {
61
65
  configPath,
62
- content: 'function' == typeof content ? await content() : await content
66
+ content: validate(rawContent, configPath)
63
67
  };
64
68
  } finally{
65
69
  unregister();
@@ -236,6 +240,7 @@ export const __webpack_modules__ = {
236
240
  function toRsbuildConfig(config) {
237
241
  return {
238
242
  dev: {
243
+ lazyCompilation: false,
239
244
  watchFiles: config.dev?.watchFiles,
240
245
  writeToDisk: config.dev?.writeToDisk ?? true,
241
246
  progressBar: config.dev?.progressBar ?? true
@@ -259,7 +264,9 @@ export const __webpack_modules__ = {
259
264
  sourceMap: config.output?.sourceMap
260
265
  },
261
266
  resolve: {
262
- alias: config.resolve?.alias
267
+ alias: config.resolve?.alias,
268
+ aliasStrategy: config.resolve?.aliasStrategy,
269
+ dedupe: config.resolve?.dedupe
263
270
  },
264
271
  source: {
265
272
  alias: config.source?.alias,
@@ -278,6 +285,7 @@ export const __webpack_modules__ = {
278
285
  headers: config.server?.headers,
279
286
  host: config.server?.host,
280
287
  port: config.server?.port,
288
+ proxy: config.server?.proxy,
281
289
  strictPort: config.server?.strictPort
282
290
  },
283
291
  plugins: config.plugins,
@@ -56,10 +56,14 @@ export const __webpack_modules__ = {
56
56
  import(`${specifier}?t=${Date.now()}`),
57
57
  __webpack_require__.e("src_config_validate_ts").then(__webpack_require__.bind(__webpack_require__, "./src/config/validate.ts"))
58
58
  ]);
59
- const content = validate('default' in exports ? exports.default : exports, configPath);
59
+ const configExport = 'default' in exports ? exports.default : exports;
60
+ const rawContent = 'function' == typeof configExport ? await configExport({
61
+ command: process.argv[2] ?? 'build',
62
+ env: process.env['NODE_ENV'] ?? 'production'
63
+ }) : await configExport;
60
64
  return {
61
65
  configPath,
62
- content: 'function' == typeof content ? await content() : await content
66
+ content: validate(rawContent, configPath)
63
67
  };
64
68
  } finally{
65
69
  unregister();
@@ -238,6 +242,7 @@ export const __webpack_modules__ = {
238
242
  function toRsbuildConfig(config) {
239
243
  return {
240
244
  dev: {
245
+ lazyCompilation: false,
241
246
  watchFiles: config.dev?.watchFiles,
242
247
  writeToDisk: config.dev?.writeToDisk ?? true,
243
248
  progressBar: config.dev?.progressBar ?? true
@@ -261,7 +266,9 @@ export const __webpack_modules__ = {
261
266
  sourceMap: config.output?.sourceMap
262
267
  },
263
268
  resolve: {
264
- alias: config.resolve?.alias
269
+ alias: config.resolve?.alias,
270
+ aliasStrategy: config.resolve?.aliasStrategy,
271
+ dedupe: config.resolve?.dedupe
265
272
  },
266
273
  source: {
267
274
  alias: config.source?.alias,
@@ -280,6 +287,7 @@ export const __webpack_modules__ = {
280
287
  headers: config.server?.headers,
281
288
  host: config.server?.host,
282
289
  port: config.server?.port,
290
+ proxy: config.server?.proxy,
283
291
  strictPort: config.server?.strictPort
284
292
  },
285
293
  plugins: config.plugins,