@lynx-js/rspeedy 0.8.7 → 0.9.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.
Files changed (163) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/bin/rspeedy.js +2 -2
  3. package/dist/cli/main.js +414 -0
  4. package/dist/cli/start.js +171 -0
  5. package/dist/index.d.ts +2971 -0
  6. package/dist/index.js +39556 -0
  7. package/dist/register/hooks.js +552 -0
  8. package/dist/register/index.js +22 -0
  9. package/dist/src_cli_build_ts.js +47 -0
  10. package/dist/src_cli_commands_ts.js +60 -0
  11. package/dist/src_cli_dev_ts.js +87 -0
  12. package/dist/src_cli_exit_ts.js +111 -0
  13. package/dist/src_cli_inspect_ts.js +42 -0
  14. package/dist/src_cli_preview_ts.js +49 -0
  15. package/dist/src_config_loadConfig_ts-src_create-rspeedy_ts.js +39311 -0
  16. package/dist/src_plugins_api_plugin_ts.js +32 -0
  17. package/dist/src_plugins_chunkLoading_plugin_ts.js +35 -0
  18. package/dist/src_plugins_dev_plugin_ts.js +141 -0
  19. package/dist/src_plugins_index_ts.js +60 -0
  20. package/dist/src_plugins_inspect_plugin_ts.js +48 -0
  21. package/dist/src_plugins_minify_plugin_ts.js +85 -0
  22. package/dist/src_plugins_optimization_plugin_ts.js +25 -0
  23. package/dist/src_plugins_output_plugin_ts.js +46 -0
  24. package/dist/src_plugins_resolve_plugin_ts.js +21 -0
  25. package/dist/src_plugins_rsdoctor_plugin_ts.js +59 -0
  26. package/dist/src_plugins_sourcemap_plugin_ts.js +99 -0
  27. package/dist/src_plugins_stats_plugin_ts.js +26 -0
  28. package/dist/src_plugins_swc_plugin_ts.js +36 -0
  29. package/dist/src_plugins_target_plugin_ts.js +45 -0
  30. package/dist/src_version_ts.js +18 -0
  31. package/dist/vendors-node_modules_pnpm_chokidar_4_0_3_node_modules_chokidar_esm_index_js.js +1435 -0
  32. package/dist/vendors-node_modules_pnpm_chokidar_4_0_3_node_modules_chokidar_esm_index_js.js.LICENSE.txt +1 -0
  33. package/dist/vendors-node_modules_pnpm_commander_13_1_0_node_modules_commander_esm_mjs.js +1761 -0
  34. package/dist/vendors-node_modules_pnpm_ipaddr_js_2_2_0_node_modules_ipaddr_js_lib_ipaddr_js.js +1067 -0
  35. package/dist/vendors-node_modules_pnpm_javascript-stringify_2_1_0_node_modules_javascript-stringify_dist_i-b558be.js +416 -0
  36. package/package.json +36 -23
  37. package/LICENSE +0 -202
  38. package/lib/api.d.ts +0 -46
  39. package/lib/api.js +0 -2
  40. package/lib/cli/build.d.ts +0 -4
  41. package/lib/cli/build.js +0 -32
  42. package/lib/cli/commands.d.ts +0 -5
  43. package/lib/cli/commands.js +0 -45
  44. package/lib/cli/dev.d.ts +0 -4
  45. package/lib/cli/dev.js +0 -75
  46. package/lib/cli/exit.d.ts +0 -1
  47. package/lib/cli/exit.js +0 -51
  48. package/lib/cli/inspect.d.ts +0 -8
  49. package/lib/cli/inspect.js +0 -30
  50. package/lib/cli/main.d.ts +0 -1
  51. package/lib/cli/main.js +0 -39
  52. package/lib/cli/preview.d.ts +0 -4
  53. package/lib/cli/preview.js +0 -31
  54. package/lib/cli/start.d.ts +0 -6
  55. package/lib/cli/start.js +0 -88
  56. package/lib/config/defaults.d.ts +0 -2
  57. package/lib/config/defaults.js +0 -32
  58. package/lib/config/defineConfig.d.ts +0 -22
  59. package/lib/config/defineConfig.js +0 -24
  60. package/lib/config/dev/client.d.ts +0 -15
  61. package/lib/config/dev/client.js +0 -2
  62. package/lib/config/dev/index.d.ts +0 -173
  63. package/lib/config/dev/index.js +0 -2
  64. package/lib/config/index.d.ts +0 -172
  65. package/lib/config/index.js +0 -2
  66. package/lib/config/loadConfig.d.ts +0 -50
  67. package/lib/config/loadConfig.js +0 -98
  68. package/lib/config/mergeRspeedyConfig.d.ts +0 -36
  69. package/lib/config/mergeRspeedyConfig.js +0 -42
  70. package/lib/config/output/css-modules.d.ts +0 -84
  71. package/lib/config/output/css-modules.js +0 -2
  72. package/lib/config/output/dist-path.d.ts +0 -19
  73. package/lib/config/output/dist-path.js +0 -2
  74. package/lib/config/output/filename.d.ts +0 -167
  75. package/lib/config/output/filename.js +0 -2
  76. package/lib/config/output/index.d.ts +0 -324
  77. package/lib/config/output/index.js +0 -2
  78. package/lib/config/output/minify.d.ts +0 -80
  79. package/lib/config/output/minify.js +0 -2
  80. package/lib/config/output/source-map.d.ts +0 -68
  81. package/lib/config/output/source-map.js +0 -2
  82. package/lib/config/performance/chunk-split.d.ts +0 -192
  83. package/lib/config/performance/chunk-split.js +0 -2
  84. package/lib/config/performance/index.d.ts +0 -165
  85. package/lib/config/performance/index.js +0 -2
  86. package/lib/config/rsbuild/entry.d.ts +0 -3
  87. package/lib/config/rsbuild/entry.js +0 -31
  88. package/lib/config/rsbuild/index.d.ts +0 -4
  89. package/lib/config/rsbuild/index.js +0 -75
  90. package/lib/config/server/index.d.ts +0 -91
  91. package/lib/config/server/index.js +0 -2
  92. package/lib/config/source/decorators.d.ts +0 -43
  93. package/lib/config/source/decorators.js +0 -2
  94. package/lib/config/source/entry.d.ts +0 -84
  95. package/lib/config/source/entry.js +0 -2
  96. package/lib/config/source/index.d.ts +0 -474
  97. package/lib/config/source/index.js +0 -2
  98. package/lib/config/source/transformImport.d.ts +0 -106
  99. package/lib/config/source/transformImport.js +0 -2
  100. package/lib/config/tools/css-extract.d.ts +0 -72
  101. package/lib/config/tools/css-extract.js +0 -2
  102. package/lib/config/tools/css-loader.d.ts +0 -130
  103. package/lib/config/tools/css-loader.js +0 -2
  104. package/lib/config/tools/index.d.ts +0 -170
  105. package/lib/config/tools/index.js +0 -2
  106. package/lib/config/validate.d.ts +0 -4
  107. package/lib/config/validate.js +0 -28877
  108. package/lib/create-rspeedy.d.ts +0 -52
  109. package/lib/create-rspeedy.js +0 -49
  110. package/lib/debug.d.ts +0 -3
  111. package/lib/debug.js +0 -25
  112. package/lib/index.d.ts +0 -46
  113. package/lib/index.js +0 -11
  114. package/lib/plugins/api.plugin.d.ts +0 -3
  115. package/lib/plugins/api.plugin.js +0 -25
  116. package/lib/plugins/chunkLoading.plugin.d.ts +0 -2
  117. package/lib/plugins/chunkLoading.plugin.js +0 -43
  118. package/lib/plugins/dev.plugin.d.ts +0 -5
  119. package/lib/plugins/dev.plugin.js +0 -137
  120. package/lib/plugins/index.d.ts +0 -3
  121. package/lib/plugins/index.js +0 -49
  122. package/lib/plugins/inspect.plugin.d.ts +0 -4
  123. package/lib/plugins/inspect.plugin.js +0 -39
  124. package/lib/plugins/minify.plugin.d.ts +0 -3
  125. package/lib/plugins/minify.plugin.js +0 -89
  126. package/lib/plugins/optimization.plugin.d.ts +0 -2
  127. package/lib/plugins/optimization.plugin.js +0 -31
  128. package/lib/plugins/output.plugin.d.ts +0 -3
  129. package/lib/plugins/output.plugin.js +0 -34
  130. package/lib/plugins/resolve.plugin.d.ts +0 -2
  131. package/lib/plugins/resolve.plugin.js +0 -38
  132. package/lib/plugins/rsdoctor.plugin.d.ts +0 -3
  133. package/lib/plugins/rsdoctor.plugin.js +0 -48
  134. package/lib/plugins/sourcemap.plugin.d.ts +0 -2
  135. package/lib/plugins/sourcemap.plugin.js +0 -86
  136. package/lib/plugins/stats.plugin.d.ts +0 -2
  137. package/lib/plugins/stats.plugin.js +0 -20
  138. package/lib/plugins/swc.plugin.d.ts +0 -2
  139. package/lib/plugins/swc.plugin.js +0 -21
  140. package/lib/plugins/target.plugin.d.ts +0 -2
  141. package/lib/plugins/target.plugin.js +0 -22
  142. package/lib/utils/getESVersionTarget.d.ts +0 -1
  143. package/lib/utils/getESVersionTarget.js +0 -7
  144. package/lib/utils/is-ci.d.ts +0 -1
  145. package/lib/utils/is-ci.js +0 -7
  146. package/lib/utils/is-lynx.d.ts +0 -2
  147. package/lib/utils/is-lynx.js +0 -6
  148. package/lib/utils/is-web.d.ts +0 -2
  149. package/lib/utils/is-web.js +0 -6
  150. package/lib/version.d.ts +0 -4
  151. package/lib/version.js +0 -15
  152. package/lib/webpack/CompilationIdPlugin.d.ts +0 -4
  153. package/lib/webpack/CompilationIdPlugin.js +0 -20
  154. package/lib/webpack/EvalSourceMapDevToolPlugin.d.ts +0 -9
  155. package/lib/webpack/EvalSourceMapDevToolPlugin.js +0 -15
  156. package/lib/webpack/ProvidePlugin.d.ts +0 -9
  157. package/lib/webpack/ProvidePlugin.js +0 -15
  158. package/lib/webpack/SourceMapDevToolPlugin.d.ts +0 -9
  159. package/lib/webpack/SourceMapDevToolPlugin.js +0 -15
  160. package/register/data.d.ts +0 -9
  161. package/register/hooks.js +0 -146
  162. package/register/index.js +0 -47
  163. /package/{register → dist/register}/index.d.ts +0 -0
@@ -1,52 +0,0 @@
1
- import type { CreateRsbuildOptions, 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
- * Rspeedy automatically loads the .env file by default, utilizing the [Rsbuild API](https://rsbuild.dev/api/javascript-api/core#load-env-variables).
27
- * You can use the environment variables defined in the .env file within your code by accessing them via `import.meta.env.FOO` or `process.env.Foo`.
28
- * @see https://rsbuild.dev/guide/advanced/env-vars#env-file
29
- * @defaultValue true
30
- */
31
- loadEnv?: CreateRsbuildOptions['loadEnv'];
32
- }
33
- /**
34
- * The `createRspeedy` method can let you create a Rspeedy instance and you can customize the build or development process in Node.js Runtime.
35
- *
36
- * @param options - {@link CreateRspeedyOptions}
37
- * @returns - Rspeedy instance.
38
- *
39
- * @example
40
- *
41
- * ```ts
42
- * import { createRspeedy } from '@lynx-js/rspeedy'
43
- *
44
- * void async function () {
45
- * const rspeedy = await createRspeedy({})
46
- * await rspeedy.build()
47
- * }()
48
- * ```
49
- *
50
- * @public
51
- */
52
- export declare function createRspeedy({ cwd, rspeedyConfig, loadEnv }: CreateRspeedyOptions): Promise<RspeedyInstance>;
@@ -1,49 +0,0 @@
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 = {}, loadEnv = true }) {
28
- const config = applyDefaultRspeedyConfig(rspeedyConfig);
29
- const [rspeedy, { applyDefaultPlugins }] = await Promise.all([
30
- createRsbuild({
31
- cwd,
32
- loadEnv,
33
- rsbuildConfig: toRsbuildConfig(config),
34
- }),
35
- import('./plugins/index.js'),
36
- ]);
37
- await applyDefaultPlugins(rspeedy, config);
38
- const inspectConfig = rspeedy.inspectConfig.bind(rspeedy);
39
- return Object.assign(rspeedy, {
40
- getRspeedyConfig: () => config,
41
- async inspectConfig(options) {
42
- const result = await inspectConfig(options);
43
- const { inspectRspeedyConfig } = await import('./plugins/inspect.plugin.js');
44
- await inspectRspeedyConfig(rspeedyConfig, path.resolve(options.outputPath ?? rspeedy.context.distPath, '.rsbuild/rspeedy.config.js'), options.verbose ?? false);
45
- return result;
46
- },
47
- });
48
- }
49
- //# sourceMappingURL=create-rspeedy.js.map
package/lib/debug.d.ts DELETED
@@ -1,3 +0,0 @@
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 DELETED
@@ -1,25 +0,0 @@
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 DELETED
@@ -1,46 +0,0 @@
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 { mergeRspeedyConfig } from './config/mergeRspeedyConfig.js';
21
- export { defineConfig } from './config/defineConfig.js';
22
- export { loadConfig, type LoadConfigOptions, type LoadConfigResult, } from './config/loadConfig.js';
23
- export type { Config } from './config/index.js';
24
- export type { Dev } from './config/dev/index.js';
25
- export type { Client as DevClient } from './config/dev/client.js';
26
- export type { CssModules, CssModuleLocalsConvention, } from './config/output/css-modules.js';
27
- export type { DistPath } from './config/output/dist-path.js';
28
- export type { Filename } from './config/output/filename.js';
29
- export type { Minify } from './config/output/minify.js';
30
- export type { SourceMap } from './config/output/source-map.js';
31
- export type { Output } from './config/output/index.js';
32
- export type { Performance } from './config/performance/index.js';
33
- export type { ChunkSplit, ChunkSplitBySize, ChunkSplitCustom, } from './config/performance/chunk-split.js';
34
- export type { ConsoleType } from './config/performance/index.js';
35
- export type { RsbuildPlugin, RsbuildPluginAPI } from '@rsbuild/core';
36
- export { rspack } from '@rsbuild/core';
37
- export type { Rspack } from '@rsbuild/core';
38
- export type { Server } from './config/server/index.js';
39
- export type { Source } from './config/source/index.js';
40
- export type { Decorators } from './config/source/decorators.js';
41
- export type { Entry, EntryDescription } from './config/source/entry.js';
42
- export type { TransformImport } from './config/source/transformImport.js';
43
- export type { CssExtract, CssExtractRspackLoaderOptions, CssExtractRspackPluginOptions, } from './config/tools/css-extract.js';
44
- export type { CssLoader, CssLoaderModules } from './config/tools/css-loader.js';
45
- export type { RsdoctorRspackPluginOptions, Tools, } from './config/tools/index.js';
46
- export { version, rsbuildVersion, rspackVersion } from './version.js';
package/lib/index.js DELETED
@@ -1,11 +0,0 @@
1
- export { createRspeedy, } from './create-rspeedy.js';
2
- export { logger } from '@rsbuild/core';
3
- export { mergeRspeedyConfig } from './config/mergeRspeedyConfig.js';
4
- // Config
5
- export { defineConfig } from './config/defineConfig.js';
6
- export { loadConfig, } from './config/loadConfig.js';
7
- // Rspack instance
8
- export { rspack } from '@rsbuild/core';
9
- // Version
10
- export { version, rsbuildVersion, rspackVersion } from './version.js';
11
- //# sourceMappingURL=index.js.map
@@ -1,3 +0,0 @@
1
- import type { RsbuildPlugin } from '@rsbuild/core';
2
- import type { Config } from '../config/index.js';
3
- export declare function pluginAPI(config: Config): RsbuildPlugin;
@@ -1,25 +0,0 @@
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
@@ -1,2 +0,0 @@
1
- import type { RsbuildPlugin } from '@rsbuild/core';
2
- export declare function pluginChunkLoading(): RsbuildPlugin;
@@ -1,43 +0,0 @@
1
- import { ChunkLoadingWebpackPlugin } from '@lynx-js/chunk-loading-webpack-plugin';
2
- import { isLynx } from '../utils/is-lynx.js';
3
- import { isWeb } from '../utils/is-web.js';
4
- export function pluginChunkLoading() {
5
- return {
6
- name: 'lynx:rsbuild:chunk-loading',
7
- setup(api) {
8
- api.modifyBundlerChain((chain, { environment }) => {
9
- if (isWeb(environment)) {
10
- chain
11
- .output
12
- .chunkLoading('import-scripts')
13
- .end();
14
- return;
15
- }
16
- if (isLynx(environment)) {
17
- // dprint-ignore
18
- chain
19
- .plugin('lynx:chunk-loading')
20
- .use(ChunkLoadingWebpackPlugin)
21
- .end()
22
- .output
23
- // Rspack needs `chunkLoading: 'require'` since we use runtimeModule hook
24
- // to override the chunk loading runtime.
25
- .chunkLoading('require')
26
- .chunkFormat('commonjs')
27
- .iife(false)
28
- .end();
29
- }
30
- });
31
- api.modifyWebpackChain((chain, { environment }) => {
32
- if (isLynx(environment)) {
33
- chain
34
- .output
35
- // For webpack, we directly use `chunkLoading: 'lynx'`.
36
- .chunkLoading('lynx')
37
- .end();
38
- }
39
- });
40
- },
41
- };
42
- }
43
- //# sourceMappingURL=chunkLoading.plugin.js.map
@@ -1,5 +0,0 @@
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', isInternal?: boolean): Promise<string>;
@@ -1,137 +0,0 @@
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
- if (server?.base) {
43
- if (assetPrefix.endsWith('/')) {
44
- assetPrefix = assetPrefix.slice(0, -1);
45
- }
46
- assetPrefix = `${assetPrefix}${server.base}/`;
47
- }
48
- debug(`dev.assetPrefix is normalized to ${assetPrefix}`);
49
- api.modifyRsbuildConfig((config, { mergeRsbuildConfig }) => {
50
- return mergeRsbuildConfig(config, {
51
- dev: {
52
- assetPrefix,
53
- client: {
54
- // Lynx cannot use `location.hostname`.
55
- host: hostname,
56
- },
57
- },
58
- });
59
- });
60
- const require = createRequire(import.meta.url);
61
- api.modifyBundlerChain((chain, { isProd }) => {
62
- if (isProd) {
63
- return;
64
- }
65
- const rsbuildPath = require.resolve('@rsbuild/core');
66
- // dprint-ignore
67
- chain
68
- .resolve
69
- .alias
70
- .set('webpack/hot/log.js', require.resolve('@rspack/core/hot/log', {
71
- paths: [rsbuildPath],
72
- }))
73
- .set('webpack/hot/emitter.js', require.resolve('@rspack/core/hot/emitter', {
74
- paths: [rsbuildPath],
75
- }))
76
- .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`)
77
- .set('@rspack/core/hot/dev-server', require.resolve('@rspack/core/hot/dev-server', {
78
- paths: [rsbuildPath],
79
- }))
80
- .end()
81
- .end()
82
- .plugin('lynx.hmr.provide')
83
- .use(ProvidePlugin, [
84
- {
85
- WebSocket: [
86
- options?.client?.websocketTransport ?? require.resolve('@lynx-js/websocket'),
87
- 'default',
88
- ],
89
- __webpack_dev_server_client__: [require.resolve('../../client/hmr/WebSocketClient.js'), 'default'],
90
- }
91
- ])
92
- .end()
93
- .plugin('lynx.hmr.compilation-id')
94
- .use(CompilationIdPlugin, [])
95
- .end();
96
- });
97
- },
98
- };
99
- }
100
- export async function findIp(family, isInternal = false) {
101
- const [{ default: ipaddr }, os,] = await Promise.all([
102
- import('ipaddr.js'),
103
- import('node:os'),
104
- ]);
105
- let host;
106
- Object.values(os.networkInterfaces())
107
- .flatMap((networks) => networks ?? [])
108
- .filter((network) => {
109
- if (!network || !network.address) {
110
- return false;
111
- }
112
- if (network.family !== `IP${family}`) {
113
- return false;
114
- }
115
- if (network.internal !== isInternal) {
116
- return false;
117
- }
118
- if (family === 'v6') {
119
- const range = ipaddr.parse(network.address).range();
120
- if (range !== 'ipv4Mapped' && range !== 'uniqueLocal') {
121
- return false;
122
- }
123
- }
124
- return network.address;
125
- })
126
- .forEach((network) => {
127
- host = network.address;
128
- if (host.includes(':')) {
129
- host = `[${host}]`;
130
- }
131
- });
132
- if (!host) {
133
- throw new Error(`No valid IP found`);
134
- }
135
- return host;
136
- }
137
- //# sourceMappingURL=dev.plugin.js.map
@@ -1,3 +0,0 @@
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>;
@@ -1,49 +0,0 @@
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
@@ -1,4 +0,0 @@
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>;
@@ -1,39 +0,0 @@
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
@@ -1,3 +0,0 @@
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;
@@ -1,89 +0,0 @@
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
@@ -1,2 +0,0 @@
1
- import type { RsbuildPlugin } from '@rsbuild/core';
2
- export declare function pluginOptimization(): RsbuildPlugin;
@@ -1,31 +0,0 @@
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
@@ -1,3 +0,0 @@
1
- import type { RsbuildPlugin } from '@rsbuild/core';
2
- import type { Output } from '../config/output/index.js';
3
- export declare function pluginOutput(options?: Output): RsbuildPlugin;