@lynx-js/rspeedy 0.8.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.
Files changed (127) hide show
  1. package/CHANGELOG.md +208 -0
  2. package/LICENSE +202 -0
  3. package/README.md +32 -0
  4. package/bin/rspeedy.js +33 -0
  5. package/client/hmr/WebSocketClient.js +65 -0
  6. package/client.d.ts +5 -0
  7. package/lib/api.d.ts +46 -0
  8. package/lib/api.js +2 -0
  9. package/lib/cli/build.d.ts +4 -0
  10. package/lib/cli/build.js +32 -0
  11. package/lib/cli/commands.d.ts +5 -0
  12. package/lib/cli/commands.js +45 -0
  13. package/lib/cli/dev.d.ts +4 -0
  14. package/lib/cli/dev.js +75 -0
  15. package/lib/cli/exit.d.ts +1 -0
  16. package/lib/cli/exit.js +51 -0
  17. package/lib/cli/inspect.d.ts +8 -0
  18. package/lib/cli/inspect.js +30 -0
  19. package/lib/cli/main.d.ts +1 -0
  20. package/lib/cli/main.js +39 -0
  21. package/lib/cli/preview.d.ts +4 -0
  22. package/lib/cli/preview.js +31 -0
  23. package/lib/cli/start.d.ts +6 -0
  24. package/lib/cli/start.js +88 -0
  25. package/lib/config/defaults.d.ts +2 -0
  26. package/lib/config/defaults.js +32 -0
  27. package/lib/config/defineConfig.d.ts +22 -0
  28. package/lib/config/defineConfig.js +24 -0
  29. package/lib/config/dev/client.d.ts +15 -0
  30. package/lib/config/dev/client.js +2 -0
  31. package/lib/config/dev/index.d.ts +133 -0
  32. package/lib/config/dev/index.js +2 -0
  33. package/lib/config/index.d.ts +172 -0
  34. package/lib/config/index.js +2 -0
  35. package/lib/config/loadConfig.d.ts +50 -0
  36. package/lib/config/loadConfig.js +98 -0
  37. package/lib/config/output/css-modules.d.ts +84 -0
  38. package/lib/config/output/css-modules.js +2 -0
  39. package/lib/config/output/dist-path.d.ts +68 -0
  40. package/lib/config/output/dist-path.js +2 -0
  41. package/lib/config/output/filename.d.ts +167 -0
  42. package/lib/config/output/filename.js +2 -0
  43. package/lib/config/output/index.d.ts +320 -0
  44. package/lib/config/output/index.js +2 -0
  45. package/lib/config/output/minify.d.ts +80 -0
  46. package/lib/config/output/minify.js +2 -0
  47. package/lib/config/output/source-map.d.ts +68 -0
  48. package/lib/config/output/source-map.js +2 -0
  49. package/lib/config/performance/chunk-split.d.ts +192 -0
  50. package/lib/config/performance/chunk-split.js +2 -0
  51. package/lib/config/performance/index.d.ts +50 -0
  52. package/lib/config/performance/index.js +2 -0
  53. package/lib/config/rsbuild/entry.d.ts +3 -0
  54. package/lib/config/rsbuild/entry.js +31 -0
  55. package/lib/config/rsbuild/index.d.ts +4 -0
  56. package/lib/config/rsbuild/index.js +70 -0
  57. package/lib/config/server/index.d.ts +47 -0
  58. package/lib/config/server/index.js +2 -0
  59. package/lib/config/source/decorators.d.ts +43 -0
  60. package/lib/config/source/decorators.js +2 -0
  61. package/lib/config/source/entry.d.ts +84 -0
  62. package/lib/config/source/entry.js +2 -0
  63. package/lib/config/source/index.d.ts +474 -0
  64. package/lib/config/source/index.js +2 -0
  65. package/lib/config/source/transformImport.d.ts +106 -0
  66. package/lib/config/source/transformImport.js +2 -0
  67. package/lib/config/tools/css-extract.d.ts +72 -0
  68. package/lib/config/tools/css-extract.js +2 -0
  69. package/lib/config/tools/css-loader.d.ts +130 -0
  70. package/lib/config/tools/css-loader.js +2 -0
  71. package/lib/config/tools/index.d.ts +170 -0
  72. package/lib/config/tools/index.js +2 -0
  73. package/lib/config/validate.d.ts +4 -0
  74. package/lib/config/validate.js +28962 -0
  75. package/lib/create-rspeedy.d.ts +45 -0
  76. package/lib/create-rspeedy.js +48 -0
  77. package/lib/debug.d.ts +3 -0
  78. package/lib/debug.js +25 -0
  79. package/lib/index.d.ts +45 -0
  80. package/lib/index.js +10 -0
  81. package/lib/plugins/api.plugin.d.ts +3 -0
  82. package/lib/plugins/api.plugin.js +25 -0
  83. package/lib/plugins/chunkLoading.plugin.d.ts +2 -0
  84. package/lib/plugins/chunkLoading.plugin.js +30 -0
  85. package/lib/plugins/dev.plugin.d.ts +5 -0
  86. package/lib/plugins/dev.plugin.js +130 -0
  87. package/lib/plugins/index.d.ts +3 -0
  88. package/lib/plugins/index.js +49 -0
  89. package/lib/plugins/inspect.plugin.d.ts +4 -0
  90. package/lib/plugins/inspect.plugin.js +39 -0
  91. package/lib/plugins/minify.plugin.d.ts +3 -0
  92. package/lib/plugins/minify.plugin.js +89 -0
  93. package/lib/plugins/optimization.plugin.d.ts +2 -0
  94. package/lib/plugins/optimization.plugin.js +31 -0
  95. package/lib/plugins/output.plugin.d.ts +3 -0
  96. package/lib/plugins/output.plugin.js +34 -0
  97. package/lib/plugins/resolve.plugin.d.ts +2 -0
  98. package/lib/plugins/resolve.plugin.js +38 -0
  99. package/lib/plugins/rsdoctor.plugin.d.ts +3 -0
  100. package/lib/plugins/rsdoctor.plugin.js +41 -0
  101. package/lib/plugins/sourcemap.plugin.d.ts +2 -0
  102. package/lib/plugins/sourcemap.plugin.js +84 -0
  103. package/lib/plugins/stats.plugin.d.ts +2 -0
  104. package/lib/plugins/stats.plugin.js +20 -0
  105. package/lib/plugins/swc.plugin.d.ts +2 -0
  106. package/lib/plugins/swc.plugin.js +21 -0
  107. package/lib/plugins/target.plugin.d.ts +2 -0
  108. package/lib/plugins/target.plugin.js +12 -0
  109. package/lib/utils/getESVersionTarget.d.ts +1 -0
  110. package/lib/utils/getESVersionTarget.js +7 -0
  111. package/lib/utils/is-ci.d.ts +1 -0
  112. package/lib/utils/is-ci.js +7 -0
  113. package/lib/version.d.ts +4 -0
  114. package/lib/version.js +15 -0
  115. package/lib/webpack/CompilationIdPlugin.d.ts +4 -0
  116. package/lib/webpack/CompilationIdPlugin.js +20 -0
  117. package/lib/webpack/EvalSourceMapDevToolPlugin.d.ts +9 -0
  118. package/lib/webpack/EvalSourceMapDevToolPlugin.js +15 -0
  119. package/lib/webpack/ProvidePlugin.d.ts +9 -0
  120. package/lib/webpack/ProvidePlugin.js +15 -0
  121. package/lib/webpack/SourceMapDevToolPlugin.d.ts +9 -0
  122. package/lib/webpack/SourceMapDevToolPlugin.js +15 -0
  123. package/package.json +83 -0
  124. package/register/data.d.ts +9 -0
  125. package/register/hooks.js +146 -0
  126. package/register/index.d.ts +4 -0
  127. package/register/index.js +47 -0
@@ -0,0 +1,50 @@
1
+ import type { ChunkSplit, ChunkSplitBySize, ChunkSplitCustom } from './chunk-split.js';
2
+ /**
3
+ * The type of the console method.
4
+ *
5
+ * @public
6
+ */
7
+ export type ConsoleType = 'log' | 'warn' | 'error' | 'info' | 'debug' | 'profile' | 'profileEnd' | (string & Record<never, never>);
8
+ /**
9
+ * {@inheritdoc Config.performance}
10
+ *
11
+ * @public
12
+ */
13
+ export interface Performance {
14
+ /**
15
+ * {@link Performance.chunkSplit} is used to configure the chunk splitting strategy.
16
+ */
17
+ chunkSplit?: ChunkSplit | ChunkSplitBySize | ChunkSplitCustom | undefined;
18
+ /**
19
+ * Whether to remove `console.[methodName]` in production build.
20
+ *
21
+ * @example
22
+ *
23
+ * - Remove all `console` methods
24
+ *
25
+ * ```ts
26
+ * import { defineConfig } from '@lynx-js/rspeedy'
27
+ *
28
+ * export default defineConfig({
29
+ * performance: {
30
+ * removeConsole: true,
31
+ * },
32
+ * })
33
+ * ```
34
+ *
35
+ * @example
36
+ *
37
+ * - Remove specific `console` methods
38
+ *
39
+ * ```ts
40
+ * import { defineConfig } from '@lynx-js/rspeedy'
41
+ *
42
+ * export default defineConfig({
43
+ * performance: {
44
+ * removeConsole: ['log', 'warn']
45
+ * },
46
+ * })
47
+ * ```
48
+ */
49
+ removeConsole?: boolean | ConsoleType[] | undefined;
50
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ import type { RsbuildEntry } from '@rsbuild/core';
2
+ import type { Entry } from '../source/entry.js';
3
+ export declare function toRsbuildEntry(entry: Entry | undefined): RsbuildEntry;
@@ -0,0 +1,31 @@
1
+ import { debug, debugList } from '../../debug.js';
2
+ const DEFAULT_ENTRY = './src/index.js';
3
+ export function toRsbuildEntry(entry) {
4
+ // Default value
5
+ if (entry === undefined) {
6
+ debug(`Using default entry ${DEFAULT_ENTRY}`);
7
+ return {
8
+ main: DEFAULT_ENTRY,
9
+ };
10
+ }
11
+ // Single entry
12
+ if (Array.isArray(entry) || typeof entry === 'string') {
13
+ debug(() => `Using single entry ${[''].concat(entry).join('\n - ')}`);
14
+ return { main: entry };
15
+ }
16
+ return Object.fromEntries(Object.entries(entry).map(([key, value]) => {
17
+ if (Array.isArray(value) || typeof value === 'string') {
18
+ debugList(`Using multiple entries - ${key}`, value);
19
+ return [key, { import: value }];
20
+ }
21
+ debugList(`Using multiple entries - ${key}`, value.import ?? DEFAULT_ENTRY);
22
+ if (value.import === undefined) {
23
+ return [
24
+ key,
25
+ { ...value, import: DEFAULT_ENTRY },
26
+ ];
27
+ }
28
+ return [key, value];
29
+ }));
30
+ }
31
+ //# sourceMappingURL=entry.js.map
@@ -0,0 +1,4 @@
1
+ import type { RsbuildConfig } from '@rsbuild/core';
2
+ import type { UndefinedOnPartialDeep } from 'type-fest';
3
+ import type { Config } from '../index.js';
4
+ export declare function toRsbuildConfig(config: Config): UndefinedOnPartialDeep<RsbuildConfig>;
@@ -0,0 +1,70 @@
1
+ import { toRsbuildEntry } from './entry.js';
2
+ // This is the default value from lynx-speedy.
3
+ // We may change it based on new benchmarks.
4
+ const defaultDataUriLimit = 2 * 1024;
5
+ export function toRsbuildConfig(config) {
6
+ return {
7
+ provider: config.provider,
8
+ dev: {
9
+ watchFiles: config.dev?.watchFiles,
10
+ // We expect to use different default writeToDisk with Rsbuild
11
+ writeToDisk: config.dev?.writeToDisk ?? true,
12
+ },
13
+ environments: config.environments ?? { lynx: {} },
14
+ mode: config.mode,
15
+ output: {
16
+ assetPrefix: config.output?.assetPrefix,
17
+ charset: 'utf8',
18
+ cleanDistPath: config.output?.cleanDistPath,
19
+ copy: config.output?.copy,
20
+ cssModules: config.output?.cssModules,
21
+ // We expect to use different default dataUriLimit with Rsbuild
22
+ dataUriLimit: config.output?.dataUriLimit ?? defaultDataUriLimit,
23
+ distPath: config.output?.distPath,
24
+ filenameHash: config.output?.filenameHash,
25
+ // TODO(OSS): change the default value to `linked`(or `undefined`) when OSS.
26
+ // We expect to use different default legalComments with Rsbuild
27
+ legalComments: config.output?.legalComments ?? 'none',
28
+ polyfill: 'off',
29
+ sourceMap: config.output?.sourceMap,
30
+ },
31
+ source: {
32
+ alias: config.source?.alias,
33
+ assetsInclude: config.source?.assetsInclude,
34
+ decorators: config.source?.decorators,
35
+ define: config.source?.define,
36
+ entry: toRsbuildEntry(config.source?.entry),
37
+ exclude: config.source?.exclude,
38
+ include: config.source?.include,
39
+ transformImport: config.source?.transformImport,
40
+ tsconfigPath: config.source?.tsconfigPath,
41
+ },
42
+ server: {
43
+ headers: config.server?.headers,
44
+ host: config.server?.host,
45
+ port: config.server?.port,
46
+ },
47
+ plugins: config.plugins,
48
+ performance: {
49
+ chunkSplit: config.performance?.chunkSplit,
50
+ removeConsole: toRsbuildRemoveConsole(config),
51
+ },
52
+ tools: {
53
+ bundlerChain: config.tools?.bundlerChain,
54
+ cssExtract: config.tools?.cssExtract,
55
+ cssLoader: config.tools?.cssLoader,
56
+ htmlPlugin: false,
57
+ rspack: config.tools?.rspack,
58
+ swc: config.tools?.swc,
59
+ },
60
+ };
61
+ }
62
+ function toRsbuildRemoveConsole(config) {
63
+ if (config.performance?.removeConsole === true) {
64
+ // Lynx use console as a parameter in the runtime-wrapper
65
+ // So we need to use all the console methods instead of `true` to make sure Rsbuild can remove all the console methods
66
+ return ['log', 'warn', 'error', 'info', 'debug', 'profile', 'profileEnd'];
67
+ }
68
+ return config.performance?.removeConsole;
69
+ }
70
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,47 @@
1
+ /**
2
+ * {@inheritdoc Config.server}
3
+ * @public
4
+ */
5
+ export interface Server {
6
+ /**
7
+ * Adds headers to all responses.
8
+ *
9
+ * @example
10
+ *
11
+ * ```js
12
+ * import { defineConfig } from '@lynx-js/rspeedy'
13
+ * export default defineConfig({
14
+ * server: {
15
+ * headers: {
16
+ * 'Access-Control-Allow-Origin': '**',
17
+ * },
18
+ * },
19
+ * })
20
+ * ```
21
+ */
22
+ headers?: Record<string, string | string[]> | undefined;
23
+ /**
24
+ * Specify the host that the Rspeedy Server listens to.
25
+ */
26
+ host?: string | undefined;
27
+ /**
28
+ * Specify the port that the Rspeedy Server listens to.
29
+ *
30
+ * @remarks
31
+ * By default, the server listens on port `3000` and automatically increments the port number when the port is occupied.
32
+ *
33
+ * @example
34
+ *
35
+ * Set the port to a custom value:
36
+ *
37
+ * ```js
38
+ * import { defineConfig } from '@lynx-js/rspeedy'
39
+ * export default defineConfig({
40
+ * server: {
41
+ * port: 3470,
42
+ * },
43
+ * })
44
+ * ```
45
+ */
46
+ port?: number | undefined;
47
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,43 @@
1
+ /**
2
+ * {@inheritdoc Source.decorators}
3
+ *
4
+ * @public
5
+ */
6
+ export interface Decorators {
7
+ /**
8
+ * Specify the decorator syntax version to be used.
9
+ *
10
+ * @remarks
11
+ *
12
+ * If you want to know the differences between different decorators versions, you can refer to: {@link https://github.com/tc39/proposal-decorators?tab=readme-ov-file#how-does-this-proposal-compare-to-other-versions-of-decorators | How does this proposal compare to other versions of decorators?}
13
+ *
14
+ * @example
15
+ *
16
+ * `'2022-03'` corresponds to the Stage 3 decorator proposal, equivalent to the decorator syntax supported by TypeScript 5.0 by default.
17
+ *
18
+ * ```js
19
+ * import { defineConfig } from '@lynx-js/rspeedy'
20
+ *
21
+ * export default defineConfig({
22
+ * source: {
23
+ * decorators: { version: '2022-03' },
24
+ * },
25
+ * })
26
+ * ```
27
+ *
28
+ * @example
29
+ *
30
+ * `'legacy'` corresponds to TypeScript's `experimentalDecorators: true`.
31
+ *
32
+ * ```js
33
+ * import { defineConfig } from '@lynx-js/rspeedy'
34
+ *
35
+ * export default defineConfig({
36
+ * source: {
37
+ * decorators: { version: 'legacy' },
38
+ * },
39
+ * })
40
+ * ```
41
+ */
42
+ version?: 'legacy' | '2022-03';
43
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=decorators.js.map
@@ -0,0 +1,84 @@
1
+ /**
2
+ * The `EntryDescription` describes a entry. It is useful when the project has multiple entries with different configuration.
3
+ *
4
+ * @remarks
5
+ * It is similar with the {@link https://www.rspack.dev/config/entry#entry-description-object | Entry Description Object} of Rspack.
6
+ * But only a few properties that Lynx supports is allowed.
7
+ *
8
+ * @public
9
+ */
10
+ export interface EntryDescription {
11
+ /**
12
+ * The path to the entry module(s).
13
+ *
14
+ * @remarks
15
+ *
16
+ * If no value is provided, the default value `src/index.js` will be used.
17
+ *
18
+ * @defaultValue `'./src/index.js'`
19
+ */
20
+ import?: string | string[] | undefined;
21
+ /**
22
+ * This is an important option when using on-demand-loading or loading external resources like images, files, etc. If an incorrect value is specified you'll receive 404 errors while loading these resources.
23
+ *
24
+ * @see https://webpack.js.org/configuration/output/#outputpublicpath
25
+ */
26
+ publicPath?: string | undefined;
27
+ }
28
+ /**
29
+ * {@inheritdoc Source.entry}
30
+ *
31
+ * @example
32
+ *
33
+ * - Use a single entry:
34
+ *
35
+ * ```js
36
+ * import { defineConfig } from '@lynx-js/rspeedy'
37
+ * export default defineConfig({
38
+ * entry: './src/pages/main/index.js',
39
+ * })
40
+ * ```
41
+ *
42
+ * @example
43
+ *
44
+ * - Use a single entry with multiple entry modules:
45
+ *
46
+ * ```js
47
+ * import { defineConfig } from '@lynx-js/rspeedy'
48
+ * export default defineConfig({
49
+ * entry: ['./src/prefetch.js', './src/pages/main/index.js'],
50
+ * })
51
+ * ```
52
+ *
53
+ * @example
54
+ *
55
+ * - Use multiple entries(with multiple entry modules):
56
+ *
57
+ * ```js
58
+ * import { defineConfig } from '@lynx-js/rspeedy'
59
+ * export default defineConfig({
60
+ * entry: {
61
+ * foo: './src/pages/foo/index.js',
62
+ * bar: ['./src/pages/bar/index.js', './src/post.js'], // multiple entry modules is allowed
63
+ * },
64
+ * })
65
+ * ```
66
+ *
67
+ * @example
68
+ *
69
+ * - Use multiple entries with {@link EntryDescription}:
70
+ *
71
+ * ```js
72
+ * import { defineConfig } from '@lynx-js/rspeedy'
73
+ * export default defineConfig({
74
+ * entry: {
75
+ * foo: './src/pages/foo/index.js',
76
+ * bar: {
77
+ * import: ['./src/prefetch.js', './src/pages/bar'],
78
+ * },
79
+ * },
80
+ * })
81
+ * ```
82
+ * @public
83
+ */
84
+ export type Entry = string | string[] | Record<string, string | string[] | EntryDescription>;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=entry.js.map