@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,45 @@
1
+ import type { RsbuildInstance } from '@rsbuild/core';
2
+ import type { Config } from './config/index.js';
3
+ /**
4
+ * The instance of Rspeedy.
5
+ *
6
+ * @public
7
+ */
8
+ export type RspeedyInstance = RsbuildInstance & {
9
+ getRspeedyConfig(): Config;
10
+ };
11
+ /**
12
+ * The options of `createRspeedy` method.
13
+ *
14
+ * @public
15
+ */
16
+ export interface CreateRspeedyOptions {
17
+ /**
18
+ * The root path of the current build.
19
+ */
20
+ cwd?: string;
21
+ /**
22
+ * The config of Rspeedy.
23
+ */
24
+ rspeedyConfig?: Config;
25
+ }
26
+ /**
27
+ * The `createRspeedy` method can let you create a Rspeedy instance and you can customize the build or development process in Node.js Runtime.
28
+ *
29
+ * @param options - {@link CreateRspeedyOptions}
30
+ * @returns - Rspeedy instance.
31
+ *
32
+ * @example
33
+ *
34
+ * ```ts
35
+ * import { createRspeedy } from '@lynx-js/rspeedy'
36
+ *
37
+ * void async function () {
38
+ * const rspeedy = await createRspeedy({})
39
+ * await rspeedy.build()
40
+ * }()
41
+ * ```
42
+ *
43
+ * @public
44
+ */
45
+ export declare function createRspeedy({ cwd, rspeedyConfig }: CreateRspeedyOptions): Promise<RspeedyInstance>;
@@ -0,0 +1,48 @@
1
+ // Copyright 2024 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import path from 'node:path';
5
+ import { createRsbuild } from '@rsbuild/core';
6
+ import { applyDefaultRspeedyConfig } from './config/defaults.js';
7
+ import { toRsbuildConfig } from './config/rsbuild/index.js';
8
+ /**
9
+ * The `createRspeedy` method can let you create a Rspeedy instance and you can customize the build or development process in Node.js Runtime.
10
+ *
11
+ * @param options - {@link CreateRspeedyOptions}
12
+ * @returns - Rspeedy instance.
13
+ *
14
+ * @example
15
+ *
16
+ * ```ts
17
+ * import { createRspeedy } from '@lynx-js/rspeedy'
18
+ *
19
+ * void async function () {
20
+ * const rspeedy = await createRspeedy({})
21
+ * await rspeedy.build()
22
+ * }()
23
+ * ```
24
+ *
25
+ * @public
26
+ */
27
+ export async function createRspeedy({ cwd = process.cwd(), rspeedyConfig = {} }) {
28
+ const config = applyDefaultRspeedyConfig(rspeedyConfig);
29
+ const [rspeedy, { applyDefaultPlugins }] = await Promise.all([
30
+ createRsbuild({
31
+ cwd,
32
+ rsbuildConfig: toRsbuildConfig(config),
33
+ }),
34
+ import('./plugins/index.js'),
35
+ ]);
36
+ await applyDefaultPlugins(rspeedy, config);
37
+ const inspectConfig = rspeedy.inspectConfig.bind(rspeedy);
38
+ return Object.assign(rspeedy, {
39
+ getRspeedyConfig: () => config,
40
+ async inspectConfig(options) {
41
+ const result = await inspectConfig(options);
42
+ const { inspectRspeedyConfig } = await import('./plugins/inspect.plugin.js');
43
+ await inspectRspeedyConfig(rspeedyConfig, path.resolve(options.outputPath ?? rspeedy.context.distPath, '.rsbuild/rspeedy.config.js'), options.verbose ?? false);
44
+ return result;
45
+ },
46
+ });
47
+ }
48
+ //# sourceMappingURL=create-rspeedy.js.map
package/lib/debug.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare const isDebug: () => boolean;
2
+ export declare const debug: (message: string | (() => string)) => void;
3
+ export declare const debugList: (prefix: string, messages: string | string[]) => void;
package/lib/debug.js ADDED
@@ -0,0 +1,25 @@
1
+ // Copyright 2024 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { logger } from '@rsbuild/core';
5
+ import color from 'picocolors';
6
+ export const isDebug = () => {
7
+ if (!process.env['DEBUG']) {
8
+ return false;
9
+ }
10
+ const values = process.env['DEBUG'].toLocaleLowerCase().split(',');
11
+ return ['rsbuild', 'rspeedy', '*'].some((key) => values.includes(key));
12
+ };
13
+ const label = color.bgCyan('lynx');
14
+ export const debug = (message) => {
15
+ if (isDebug()) {
16
+ const result = typeof message === 'string' ? message : message();
17
+ // Add `logger.level` since `logger.debug` will not print when `DEBUG=rspeedy`
18
+ logger.level = 'verbose';
19
+ logger.debug(`${label} ${result}`);
20
+ }
21
+ };
22
+ export const debugList = (prefix, messages) => {
23
+ return debug(() => `${prefix} ${[''].concat(messages).join('\n - ')}`);
24
+ };
25
+ //# sourceMappingURL=debug.js.map
package/lib/index.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * The document contains all the configurations of the `@lynx-js/rspeedy` package.
5
+ *
6
+ * @example
7
+ *
8
+ * Use `lynx.config.ts` with {@link defineConfig} to get better TypeScript intellisense.
9
+ *
10
+ * ```ts
11
+ * import { defineConfig } from '@lynx-js/rspeedy'
12
+ * export default defineConfig({
13
+ * entry: './src/index.tsx',
14
+ * })
15
+ * ```
16
+ */
17
+ export type { ExposedAPI } from './api.js';
18
+ export { createRspeedy, type RspeedyInstance, type CreateRspeedyOptions, } from './create-rspeedy.js';
19
+ export { logger } from '@rsbuild/core';
20
+ export { defineConfig } from './config/defineConfig.js';
21
+ export { loadConfig, type LoadConfigOptions, type LoadConfigResult, } from './config/loadConfig.js';
22
+ export type { Config } from './config/index.js';
23
+ export type { Dev } from './config/dev/index.js';
24
+ export type { Client as DevClient } from './config/dev/client.js';
25
+ export type { CssModules, CssModuleLocalsConvention, } from './config/output/css-modules.js';
26
+ export type { DistPath } from './config/output/dist-path.js';
27
+ export type { Filename } from './config/output/filename.js';
28
+ export type { Minify } from './config/output/minify.js';
29
+ export type { SourceMap } from './config/output/source-map.js';
30
+ export type { Output } from './config/output/index.js';
31
+ export type { Performance } from './config/performance/index.js';
32
+ export type { ChunkSplit, ChunkSplitBySize, ChunkSplitCustom, } from './config/performance/chunk-split.js';
33
+ export type { ConsoleType } from './config/performance/index.js';
34
+ export type { RsbuildPlugin, RsbuildPluginAPI } from '@rsbuild/core';
35
+ export { rspack } from '@rsbuild/core';
36
+ export type { Rspack } from '@rsbuild/core';
37
+ export type { Server } from './config/server/index.js';
38
+ export type { Source } from './config/source/index.js';
39
+ export type { Decorators } from './config/source/decorators.js';
40
+ export type { Entry, EntryDescription } from './config/source/entry.js';
41
+ export type { TransformImport } from './config/source/transformImport.js';
42
+ export type { CssExtract, CssExtractRspackLoaderOptions, CssExtractRspackPluginOptions, } from './config/tools/css-extract.js';
43
+ export type { CssLoader, CssLoaderModules } from './config/tools/css-loader.js';
44
+ export type { RsdoctorRspackPluginOptions, Tools, } from './config/tools/index.js';
45
+ export { version, rsbuildVersion, rspackVersion } from './version.js';
package/lib/index.js ADDED
@@ -0,0 +1,10 @@
1
+ export { createRspeedy, } from './create-rspeedy.js';
2
+ export { logger } from '@rsbuild/core';
3
+ // Config
4
+ export { defineConfig } from './config/defineConfig.js';
5
+ export { loadConfig, } from './config/loadConfig.js';
6
+ // Rspack instance
7
+ export { rspack } from '@rsbuild/core';
8
+ // Version
9
+ export { version, rsbuildVersion, rspackVersion } from './version.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,3 @@
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ import type { Config } from '../config/index.js';
3
+ export declare function pluginAPI(config: Config): RsbuildPlugin;
@@ -0,0 +1,25 @@
1
+ // Copyright 2024 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { logger } from '@rsbuild/core';
5
+ import { debug } from '../debug.js';
6
+ import { version } from '../version.js';
7
+ const sAPI = Symbol.for('rspeedy.api');
8
+ export function pluginAPI(config) {
9
+ return {
10
+ name: 'lynx:rsbuild:plugin-api',
11
+ setup(api) {
12
+ api.expose(sAPI, {
13
+ config,
14
+ debug,
15
+ async exit(code) {
16
+ const { exit } = await import('../cli/exit.js');
17
+ return exit(code);
18
+ },
19
+ logger,
20
+ version,
21
+ });
22
+ },
23
+ };
24
+ }
25
+ //# sourceMappingURL=api.plugin.js.map
@@ -0,0 +1,2 @@
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ export declare function pluginChunkLoading(): RsbuildPlugin;
@@ -0,0 +1,30 @@
1
+ import { ChunkLoadingWebpackPlugin } from '@lynx-js/chunk-loading-webpack-plugin';
2
+ export function pluginChunkLoading() {
3
+ return {
4
+ name: 'lynx:rsbuild:chunk-loading',
5
+ setup(api) {
6
+ api.modifyBundlerChain(chain => {
7
+ // dprint-ignore
8
+ chain
9
+ .plugin('lynx:chunk-loading')
10
+ .use(ChunkLoadingWebpackPlugin)
11
+ .end()
12
+ .output
13
+ // Rspack needs `chunkLoading: 'require'` since we use runtimeModule hook
14
+ // to override the chunk loading runtime.
15
+ .chunkLoading('require')
16
+ .chunkFormat('commonjs')
17
+ .iife(false)
18
+ .end();
19
+ });
20
+ api.modifyWebpackChain(chain => {
21
+ chain
22
+ .output
23
+ // For webpack, we directly use `chunkLoading: 'lynx'`.
24
+ .chunkLoading('lynx')
25
+ .end();
26
+ });
27
+ },
28
+ };
29
+ }
30
+ //# sourceMappingURL=chunkLoading.plugin.js.map
@@ -0,0 +1,5 @@
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ import type { Dev } from '../config/dev/index.js';
3
+ import type { Server } from '../config/server/index.js';
4
+ export declare function pluginDev(options?: Dev, server?: Server): RsbuildPlugin;
5
+ export declare function findIp(family: 'v4' | 'v6'): Promise<string>;
@@ -0,0 +1,130 @@
1
+ // Copyright 2024 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { createRequire } from 'node:module';
5
+ import { logger } from '@rsbuild/core';
6
+ import color from 'picocolors';
7
+ import { debug } from '../debug.js';
8
+ import { CompilationIdPlugin } from '../webpack/CompilationIdPlugin.js';
9
+ import { ProvidePlugin } from '../webpack/ProvidePlugin.js';
10
+ export function pluginDev(options, server) {
11
+ return {
12
+ name: 'lynx:rsbuild:dev',
13
+ async setup(api) {
14
+ const hostname = server?.host ?? await findIp('v4');
15
+ let assetPrefix = options?.assetPrefix;
16
+ switch (typeof assetPrefix) {
17
+ case 'string': {
18
+ if (server?.port !== undefined) {
19
+ // We should change the port of `assetPrefix` when `server.port` is set.
20
+ const hasPortPlaceholder = assetPrefix.includes('<port>');
21
+ if (!hasPortPlaceholder) {
22
+ // There is not `<port>` in `dev.assetPrefix`.
23
+ const assetPrefixURL = new URL(assetPrefix);
24
+ if (assetPrefixURL.port !== String(server.port)) {
25
+ logger.warn(`Setting different port values in ${color.cyan('server.port')} and ${color.cyan('dev.assetPrefix')}. Using server.port(${color.cyan(server.port)}) to make HMR work.`);
26
+ assetPrefixURL.port = String(server.port);
27
+ assetPrefix = assetPrefixURL.toString();
28
+ }
29
+ }
30
+ }
31
+ break;
32
+ }
33
+ case 'undefined':
34
+ case 'boolean': {
35
+ if (options?.assetPrefix !== false) {
36
+ // assetPrefix === true || assetPrefix === undefined
37
+ assetPrefix = `http://${hostname}:<port>/`;
38
+ }
39
+ break;
40
+ }
41
+ }
42
+ debug(`dev.assetPrefix is normalized to ${assetPrefix}`);
43
+ api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {
44
+ return mergeRsbuildConfig(config, {
45
+ dev: {
46
+ assetPrefix,
47
+ client: {
48
+ // Lynx cannot use `location.hostname`.
49
+ host: hostname,
50
+ },
51
+ },
52
+ });
53
+ });
54
+ const require = createRequire(import.meta.url);
55
+ api.modifyBundlerChain((chain, { isProd }) => {
56
+ if (isProd) {
57
+ return;
58
+ }
59
+ const rsbuildPath = require.resolve('@rsbuild/core');
60
+ // dprint-ignore
61
+ chain
62
+ .resolve
63
+ .alias
64
+ .set('webpack/hot/log.js', require.resolve('@rspack/core/hot/log', {
65
+ paths: [rsbuildPath],
66
+ }))
67
+ .set('webpack/hot/emitter.js', require.resolve('@rspack/core/hot/emitter', {
68
+ paths: [rsbuildPath],
69
+ }))
70
+ .set('@lynx-js/webpack-dev-transport/client', `${require.resolve('@lynx-js/webpack-dev-transport/client')}?hostname=${hostname}&port=${api.context.devServer?.port}&pathname=/rsbuild-hmr&hot=true&live-reload=true&protocol=ws`)
71
+ .set('@rspack/core/hot/dev-server', require.resolve('@rspack/core/hot/dev-server', {
72
+ paths: [rsbuildPath],
73
+ }))
74
+ .end()
75
+ .end()
76
+ .plugin('lynx.hmr.provide')
77
+ .use(ProvidePlugin, [
78
+ {
79
+ WebSocket: [
80
+ options?.client?.websocketTransport ?? require.resolve('@lynx-js/websocket'),
81
+ 'default',
82
+ ],
83
+ __webpack_dev_server_client__: [require.resolve('../../client/hmr/WebSocketClient.js'), 'default'],
84
+ }
85
+ ])
86
+ .end()
87
+ .plugin('lynx.hmr.compilation-id')
88
+ .use(CompilationIdPlugin, [])
89
+ .end();
90
+ });
91
+ },
92
+ };
93
+ }
94
+ export async function findIp(family) {
95
+ const [{ default: defaultGateway }, { default: ipaddr }, os,] = await Promise.all([
96
+ import('default-gateway'),
97
+ import('ipaddr.js'),
98
+ import('node:os'),
99
+ ]);
100
+ const gateway = await (async () => {
101
+ if (family === 'v4') {
102
+ const { gateway } = await defaultGateway.gateway4async();
103
+ return gateway;
104
+ }
105
+ else {
106
+ const { gateway } = await defaultGateway.gateway6async();
107
+ return gateway;
108
+ }
109
+ })();
110
+ const gatewayIp = ipaddr.parse(gateway);
111
+ // Look for the matching interface in all local interfaces.
112
+ for (const addresses of Object.values(os.networkInterfaces())) {
113
+ if (!addresses) {
114
+ continue;
115
+ }
116
+ for (const { cidr, internal } of addresses) {
117
+ if (!cidr || internal) {
118
+ continue;
119
+ }
120
+ const net = ipaddr.parseCIDR(cidr);
121
+ if (net[0]
122
+ && net[0].kind() === gatewayIp.kind()
123
+ && gatewayIp.match(net)) {
124
+ return net[0].toString();
125
+ }
126
+ }
127
+ }
128
+ throw new Error(`No valid IP found for the default gateway ${gateway}`);
129
+ }
130
+ //# sourceMappingURL=dev.plugin.js.map
@@ -0,0 +1,3 @@
1
+ import type { RsbuildInstance } from '@rsbuild/core';
2
+ import type { Config } from '../config/index.js';
3
+ export declare function applyDefaultPlugins(rsbuildInstance: RsbuildInstance, config: Config): Promise<void>;
@@ -0,0 +1,49 @@
1
+ import { debug, isDebug } from '../debug.js';
2
+ async function applyDebugPlugins(rsbuildInstance, config) {
3
+ const debugPlugins = Object.freeze([
4
+ import('./inspect.plugin.js').then(({ pluginInspect }) => pluginInspect(config)),
5
+ import('./stats.plugin.js').then(({ pluginStats }) => pluginStats()),
6
+ ]);
7
+ rsbuildInstance.addPlugins(await Promise.all(debugPlugins));
8
+ }
9
+ async function applyDefaultDevPlugins(rsbuildInstance, config) {
10
+ const devPlugins = Object.freeze([
11
+ import('./dev.plugin.js').then(({ pluginDev }) => pluginDev(config.dev, config.server)),
12
+ ]);
13
+ rsbuildInstance.addPlugins(await Promise.all(devPlugins));
14
+ }
15
+ export async function applyDefaultPlugins(rsbuildInstance, config) {
16
+ const defaultPlugins = Object.freeze([
17
+ import('./api.plugin.js').then(({ pluginAPI }) => pluginAPI(config)),
18
+ import('./chunkLoading.plugin.js').then(({ pluginChunkLoading }) => pluginChunkLoading()),
19
+ import('./minify.plugin.js').then(({ pluginMinify }) => pluginMinify(config.output?.minify)),
20
+ import('./optimization.plugin.js').then(({ pluginOptimization }) => pluginOptimization()),
21
+ import('./output.plugin.js').then(({ pluginOutput }) => pluginOutput(config.output)),
22
+ import('./resolve.plugin.js').then(({ pluginResolve }) => pluginResolve()),
23
+ import('./rsdoctor.plugin.js').then(({ pluginRsdoctor }) => pluginRsdoctor(config.tools?.rsdoctor)),
24
+ import('./sourcemap.plugin.js').then(({ pluginSourcemap }) => pluginSourcemap()),
25
+ import('./swc.plugin.js').then(({ pluginSwc }) => pluginSwc()),
26
+ import('./target.plugin.js').then(({ pluginTarget }) => pluginTarget()),
27
+ ]);
28
+ const promises = [
29
+ Promise.all(defaultPlugins).then(plugins => {
30
+ rsbuildInstance.addPlugins(plugins);
31
+ }),
32
+ ];
33
+ // TODO: replace with `isDev()` helper
34
+ if (process.env['NODE_ENV'] === 'development') {
35
+ debug('apply Rspeedy default development plugins');
36
+ promises.push(applyDefaultDevPlugins(rsbuildInstance, config));
37
+ }
38
+ if (isDebug()) {
39
+ debug('apply Rspeedy default debug plugins');
40
+ promises.push(applyDebugPlugins(rsbuildInstance, config));
41
+ }
42
+ await Promise.all(promises);
43
+ // If no `@rsbuild/plugin-css-minimizer` is applied, apply it
44
+ const { pluginCssMinimizer, PLUGIN_CSS_MINIMIZER_NAME } = await import('@rsbuild/plugin-css-minimizer');
45
+ if (!rsbuildInstance.isPluginExists(PLUGIN_CSS_MINIMIZER_NAME)) {
46
+ rsbuildInstance.addPlugins([pluginCssMinimizer()]);
47
+ }
48
+ }
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,4 @@
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ import type { Config } from '../config/index.js';
3
+ export declare function pluginInspect(config: Config): RsbuildPlugin;
4
+ export declare function inspectRspeedyConfig(config: Config, path: string, verbose: boolean): Promise<void>;
@@ -0,0 +1,39 @@
1
+ // Copyright 2024 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { mkdir, writeFile } from 'node:fs/promises';
5
+ import path, { dirname } from 'node:path';
6
+ import { logger } from '@rsbuild/core';
7
+ import { stringify } from 'javascript-stringify';
8
+ import color from 'picocolors';
9
+ import { DEFAULT_DIST_PATH_INTERMEDIATE } from '../config/output/dist-path.js';
10
+ import { debug } from '../debug.js';
11
+ export function pluginInspect(config) {
12
+ return {
13
+ name: 'lynx:rsbuild:inspect',
14
+ setup(api) {
15
+ api.onBeforeBuild(async () => {
16
+ await inspectRspeedyConfig(config,
17
+ /** path */ path.join(api.context.distPath, config.output?.distPath?.intermediate
18
+ ?? DEFAULT_DIST_PATH_INTERMEDIATE, 'rspeedy.config.js'),
19
+ /** verbose */ false);
20
+ });
21
+ },
22
+ };
23
+ }
24
+ export async function inspectRspeedyConfig(config, path, verbose) {
25
+ const stringifiedConfig = stringify(config, (value, _, stringify) => {
26
+ if (typeof value === 'function' && !verbose && value.toString().length > 100) {
27
+ return `function () { /* omitted long function */ }`;
28
+ }
29
+ return stringify(value);
30
+ }, 2);
31
+ if (!stringifiedConfig) {
32
+ debug('No Rspeedy config found, skip inspect config.');
33
+ return;
34
+ }
35
+ await mkdir(dirname(path), { recursive: true });
36
+ await writeFile(path, `export default ${stringifiedConfig}`);
37
+ logger.success(`Inspect Rspeedy config succeed, open following files to view the content: \n\n - ${color.bold(color.yellow('Rspeedy'))}: ${color.underline(path)}\n`);
38
+ }
39
+ //# sourceMappingURL=inspect.plugin.js.map
@@ -0,0 +1,3 @@
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ import type { Minify } from '../config/output/minify.js';
3
+ export declare function pluginMinify(options?: Minify | boolean): RsbuildPlugin;
@@ -0,0 +1,89 @@
1
+ import { debug } from '../debug.js';
2
+ export function pluginMinify(options) {
3
+ const defaultConfig = Object.freeze({
4
+ output: {
5
+ minify: {
6
+ js: true,
7
+ jsOptions: {
8
+ minimizerOptions: {
9
+ compress: {
10
+ /**
11
+ * the module wrapper iife need to be kept to provide the return value
12
+ * for the module loader in lynx_core.js
13
+ */
14
+ negate_iife: false,
15
+ join_vars: false,
16
+ ecma: 2015,
17
+ inline: 2,
18
+ comparisons: false,
19
+ toplevel: true,
20
+ // Allow return in module wrapper
21
+ side_effects: false,
22
+ },
23
+ format: {
24
+ keep_quoted_props: true,
25
+ comments: false,
26
+ },
27
+ mangle: {
28
+ toplevel: true,
29
+ },
30
+ },
31
+ },
32
+ css: true,
33
+ cssOptions: {
34
+ minimizerOptions: {
35
+ // Disable the default targets by passing an empty string.
36
+ targets: '',
37
+ include: {
38
+ // Lynx does not support nesting, so we enable it here.
39
+ // https://lightningcss.dev/transpilation.html#nesting
40
+ nesting: true,
41
+ // Lynx does not support double position gradients, so we enable it here.
42
+ // https://lightningcss.dev/transpilation.html#double-position-gradients
43
+ doublePositionGradients: true,
44
+ // Lynx does not support space separated color notation, so we enable it here.
45
+ // https://lightningcss.dev/transpilation.html#space-separated-color-notation
46
+ spaceSeparatedColorNotation: true,
47
+ },
48
+ exclude: {
49
+ // Lynx does not support vendor prefixes, so we exclude it here.
50
+ // https://lightningcss.dev/transpilation.html#vendor-prefixing
51
+ vendorPrefixes: true,
52
+ // Lynx does not support logical properties(`dir`, `lang`, `is`), so we exclude it here.
53
+ // https://lightningcss.dev/transpilation.html#logical-properties
54
+ logicalProperties: true,
55
+ // Lynx does support hex alpha colors, so we exclude it here.
56
+ // https://lightningcss.dev/transpilation.html#hex-alpha-colors
57
+ hexAlphaColors: true,
58
+ },
59
+ },
60
+ },
61
+ },
62
+ },
63
+ });
64
+ return {
65
+ name: 'lynx:rsbuild:minify',
66
+ setup(api) {
67
+ api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {
68
+ // Disable minification
69
+ if (options === false) {
70
+ debug(`minification disabled`);
71
+ return mergeRsbuildConfig(config, {
72
+ output: { minify: false },
73
+ });
74
+ }
75
+ const configs = [config, defaultConfig];
76
+ if (options !== true && options !== undefined) {
77
+ debug(`merging minification options`);
78
+ configs.push({
79
+ output: {
80
+ minify: options,
81
+ },
82
+ });
83
+ }
84
+ return mergeRsbuildConfig(...configs);
85
+ });
86
+ },
87
+ };
88
+ }
89
+ //# sourceMappingURL=minify.plugin.js.map
@@ -0,0 +1,2 @@
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ export declare function pluginOptimization(): RsbuildPlugin;
@@ -0,0 +1,31 @@
1
+ export function pluginOptimization() {
2
+ return {
3
+ name: 'lynx:rsbuild:optimization',
4
+ setup(api) {
5
+ api.modifyBundlerChain((chain, { CHAIN_ID, isProd }) => {
6
+ const rule = chain.module.rules.get(CHAIN_ID.RULE.JS);
7
+ chain
8
+ .module
9
+ .rule('js-override-strict')
10
+ .type(rule.get('type'))
11
+ .test(rule.get('test'))
12
+ // We do not directly apply this to `CHAIN_ID.RULE.JS` since it will not
13
+ // includes the `node_modules` by default.
14
+ .parser({
15
+ // Make all the modules as strict to avoid entry being wrapped by IIFE.
16
+ // See: https://github.com/webpack/webpack/discussions/18367
17
+ overrideStrict: 'strict',
18
+ })
19
+ .end();
20
+ if (isProd) {
21
+ // Avoid entry being wrapped by IIFE
22
+ // See: https://rspack.dev/config/optimization#optimizationavoidentryiife
23
+ chain
24
+ .optimization
25
+ .avoidEntryIife(true);
26
+ }
27
+ });
28
+ },
29
+ };
30
+ }
31
+ //# sourceMappingURL=optimization.plugin.js.map
@@ -0,0 +1,3 @@
1
+ import type { RsbuildPlugin } from '@rsbuild/core';
2
+ import type { Output } from '../config/output/index.js';
3
+ export declare function pluginOutput(options?: Output): RsbuildPlugin;
@@ -0,0 +1,34 @@
1
+ import { DEFAULT_DIST_PATH_INTERMEDIATE } from '../config/output/dist-path.js';
2
+ const defaultFilenameOptions = Object.freeze({
3
+ css: '[name]/[name].css',
4
+ });
5
+ const defaultDistPathOptions = Object.freeze({
6
+ // We override the default value of Rsbuild(`static/css`) here.
7
+ // Since all the CSS should be encoded into the template in Lynx.
8
+ css: DEFAULT_DIST_PATH_INTERMEDIATE,
9
+ });
10
+ export function pluginOutput(options) {
11
+ return {
12
+ name: 'lynx:rsbuild:output',
13
+ setup(api) {
14
+ api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {
15
+ if (!options) {
16
+ return mergeRsbuildConfig({
17
+ output: {
18
+ filename: {
19
+ css: defaultFilenameOptions.css,
20
+ },
21
+ },
22
+ }, config);
23
+ }
24
+ return mergeRsbuildConfig(config, {
25
+ output: {
26
+ distPath: Object.assign({}, defaultDistPathOptions, options.distPath),
27
+ filename: Object.assign({}, defaultFilenameOptions, options.filename),
28
+ },
29
+ });
30
+ });
31
+ },
32
+ };
33
+ }
34
+ //# sourceMappingURL=output.plugin.js.map