diff --git a/api-reports/rspeedy.json b/api-reports/rspeedy.json index eef14b7ae..b6f9c8644 100644 --- a/api-reports/rspeedy.json +++ b/api-reports/rspeedy.json @@ -289,6 +289,35 @@ "collapsed": true, "collapsible": true, "items": [ + { + "text": "buildCache", + "link": "api/rspeedy/rspeedy.performance.buildcache", + "collapsed": true, + "collapsible": true, + "items": [ + { + "text": "buildDependencies", + "link": "api/rspeedy/rspeedy.buildcache.builddependencies", + "collapsed": true, + "collapsible": false, + "items": [] + }, + { + "text": "cacheDigest", + "link": "api/rspeedy/rspeedy.buildcache.cachedigest", + "collapsed": true, + "collapsible": false, + "items": [] + }, + { + "text": "cacheDirectory", + "link": "api/rspeedy/rspeedy.buildcache.cachedirectory", + "collapsed": true, + "collapsible": false, + "items": [] + } + ] + }, { "text": "chunkSplit", "link": "api/rspeedy/rspeedy.performance.chunksplit", @@ -461,6 +490,13 @@ "collapsible": false, "items": [] }, + { + "text": "preEntry", + "link": "api/rspeedy/rspeedy.source.preentry", + "collapsed": true, + "collapsible": false, + "items": [] + }, { "text": "transformImport", "link": "api/rspeedy/rspeedy.source.transformimport", diff --git a/docs/en/api/rspeedy/rspeedy.buildcache.builddependencies.md b/docs/en/api/rspeedy/rspeedy.buildcache.builddependencies.md new file mode 100644 index 000000000..ef905eea8 --- /dev/null +++ b/docs/en/api/rspeedy/rspeedy.buildcache.builddependencies.md @@ -0,0 +1,47 @@ + + +[Home](./index.md) > [@lynx-js/rspeedy](./rspeedy.md) > [BuildCache](./rspeedy.buildcache.md) > [buildDependencies](./rspeedy.buildcache.builddependencies.md) + +## BuildCache.buildDependencies property + +> This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +An array of files containing build dependencies. Rspack will use the hash of each of these files to invalidate the persistent cache. + +**Signature:** + +```typescript +buildDependencies?: string[] | undefined; +``` + +## Remarks + +Rspeedy will use the following configuration files as the default build dependencies: + +- `package.json` + +- `tsconfig.json` (or `source.tsconfigPath`) + +- `.env`, `.env.*` + +- `tailwindcss.config.*` + +When using Rspeedy CLI, it will also automatically add `lynx.config.js` to the build dependencies. + +## Example + +Add `postcss.config.js` to the build dependencies. + +```js +import { defineConfig } from '@lynx-js/rspeedy' + +export default defineConfig({ + performance: { + buildCache: { + buildDependencies: ['postcss.config.js'], + }, + }, +}) +``` + diff --git a/docs/en/api/rspeedy/rspeedy.buildcache.cachedigest.md b/docs/en/api/rspeedy/rspeedy.buildcache.cachedigest.md new file mode 100644 index 000000000..d0213b8a6 --- /dev/null +++ b/docs/en/api/rspeedy/rspeedy.buildcache.cachedigest.md @@ -0,0 +1,33 @@ + + +[Home](./index.md) > [@lynx-js/rspeedy](./rspeedy.md) > [BuildCache](./rspeedy.buildcache.md) > [cacheDigest](./rspeedy.buildcache.cachedigest.md) + +## BuildCache.cacheDigest property + +> This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Add additional cache digests, the previous build cache will be invalidated when any value in the array changes. + +**Signature:** + +```typescript +cacheDigest?: Array | undefined; +``` + +## Example + +Add `process.env.SOME_ENV` to the cache digest. + +```js +import { defineConfig } from '@lynx-js/rspeedy' + +export default defineConfig({ + performance: { + buildCache: { + cacheDigest: [process.env.SOME_ENV], + }, + }, +}) +``` + diff --git a/docs/en/api/rspeedy/rspeedy.buildcache.cachedirectory.md b/docs/en/api/rspeedy/rspeedy.buildcache.cachedirectory.md new file mode 100644 index 000000000..b90764d90 --- /dev/null +++ b/docs/en/api/rspeedy/rspeedy.buildcache.cachedirectory.md @@ -0,0 +1,16 @@ + + +[Home](./index.md) > [@lynx-js/rspeedy](./rspeedy.md) > [BuildCache](./rspeedy.buildcache.md) > [cacheDirectory](./rspeedy.buildcache.cachedirectory.md) + +## BuildCache.cacheDirectory property + +> This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +The output directory of the cache files. + +**Signature:** + +```typescript +cacheDirectory?: string | undefined; +``` diff --git a/docs/en/api/rspeedy/rspeedy.buildcache.md b/docs/en/api/rspeedy/rspeedy.buildcache.md new file mode 100644 index 000000000..655115d75 --- /dev/null +++ b/docs/en/api/rspeedy/rspeedy.buildcache.md @@ -0,0 +1,27 @@ + + +[Home](./index.md) > [@lynx-js/rspeedy](./rspeedy.md) > [BuildCache](./rspeedy.buildcache.md) + +## BuildCache interface + +> This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Enable or configure persistent build cache. + +This feature is experimental and may be changed in the future. + +**Signature:** + +```typescript +export interface BuildCache +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [buildDependencies?](./rspeedy.buildcache.builddependencies.md) | | string\[\] \| undefined | **_(BETA)_** _(Optional)_ An array of files containing build dependencies. Rspack will use the hash of each of these files to invalidate the persistent cache. | +| [cacheDigest?](./rspeedy.buildcache.cachedigest.md) | | Array<string \| undefined> \| undefined | **_(BETA)_** _(Optional)_ Add additional cache digests, the previous build cache will be invalidated when any value in the array changes. | +| [cacheDirectory?](./rspeedy.buildcache.cachedirectory.md) | | string \| undefined | **_(BETA)_** _(Optional)_ The output directory of the cache files. | + diff --git a/docs/en/api/rspeedy/rspeedy.createrspeedy.md b/docs/en/api/rspeedy/rspeedy.createrspeedy.md index ee316316b..a67096af2 100644 --- a/docs/en/api/rspeedy/rspeedy.createrspeedy.md +++ b/docs/en/api/rspeedy/rspeedy.createrspeedy.md @@ -9,14 +9,14 @@ The `createRspeedy` method can let you create a Rspeedy instance and you can cus **Signature:** ```typescript -export declare function createRspeedy({ cwd, rspeedyConfig, loadEnv, environment }: CreateRspeedyOptions): Promise; +export declare function createRspeedy({ cwd, rspeedyConfig, loadEnv, environment, callerName, }: CreateRspeedyOptions): Promise; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| { cwd, rspeedyConfig, loadEnv, environment } | [CreateRspeedyOptions](./rspeedy.createrspeedyoptions.md) | | +| { cwd, rspeedyConfig, loadEnv, environment, callerName, } | [CreateRspeedyOptions](./rspeedy.createrspeedyoptions.md) | | **Returns:** diff --git a/docs/en/api/rspeedy/rspeedy.createrspeedyoptions.callername.md b/docs/en/api/rspeedy/rspeedy.createrspeedyoptions.callername.md new file mode 100644 index 000000000..8d3ab00e5 --- /dev/null +++ b/docs/en/api/rspeedy/rspeedy.createrspeedyoptions.callername.md @@ -0,0 +1,43 @@ + + +[Home](./index.md) > [@lynx-js/rspeedy](./rspeedy.md) > [CreateRspeedyOptions](./rspeedy.createrspeedyoptions.md) > [callerName](./rspeedy.createrspeedyoptions.callername.md) + +## CreateRspeedyOptions.callerName property + +The name of the framework or tool that is currently invoking Rsbuild. This allows plugins to tailor their behavior based on the calling context. + +**Signature:** + +```typescript +callerName?: string; +``` + +## Example + +Rsbuild plugins can access this value via `api.context.callerName`. + +```js +export function myPlugin() { + return { + name: 'my-plugin', + setup(api) { + // Log the name of the tool invoking Rsbuild + console.log(`Called by: ${api.context.callerName}`); + + // Conditionally apply plugin logic based on caller + if (api.context.callerName === 'rspeedy') { + api.modifyRsbuildConfig((config) => { + // Apply rspeedy-specific config changes + return config; + }); + } else if (api.context.callerName === 'rslib') { + api.modifyRsbuildConfig((config) => { + // Apply rslib-specific config changes + return config; + }); + } + } + }; +} +``` + diff --git a/docs/en/api/rspeedy/rspeedy.createrspeedyoptions.md b/docs/en/api/rspeedy/rspeedy.createrspeedyoptions.md index 6130d1077..e6b53be27 100644 --- a/docs/en/api/rspeedy/rspeedy.createrspeedyoptions.md +++ b/docs/en/api/rspeedy/rspeedy.createrspeedyoptions.md @@ -16,6 +16,7 @@ export interface CreateRspeedyOptions | Property | Modifiers | Type | Description | | --- | --- | --- | --- | +| [callerName?](./rspeedy.createrspeedyoptions.callername.md) | | string | _(Optional)_ The name of the framework or tool that is currently invoking Rsbuild. This allows plugins to tailor their behavior based on the calling context. | | [cwd?](./rspeedy.createrspeedyoptions.cwd.md) | | string | _(Optional)_ The root path of the current build. | | [environment?](./rspeedy.createrspeedyoptions.environment.md) | | CreateRsbuildOptions\['environment'\] | _(Optional)_ Only build specified environments. For example, passing ['lynx'] will only build the lynx environment. If not specified or passing an empty array, all environments will be built. | | [loadEnv?](./rspeedy.createrspeedyoptions.loadenv.md) | | CreateRsbuildOptions\['loadEnv'\] | _(Optional)_ Rspeedy automatically loads the .env file by default, utilizing the \[Rsbuild API\](https://rsbuild.dev/api/javascript-api/core\#load-env-variables). 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. | diff --git a/docs/en/api/rspeedy/rspeedy.md b/docs/en/api/rspeedy/rspeedy.md index df2ae9fc8..809ae193c 100644 --- a/docs/en/api/rspeedy/rspeedy.md +++ b/docs/en/api/rspeedy/rspeedy.md @@ -21,7 +21,7 @@ export default defineConfig({ | Function | Description | | --- | --- | -| [createRspeedy({ cwd, rspeedyConfig, loadEnv, environment })](./rspeedy.createrspeedy.md) | The createRspeedy method can let you create a Rspeedy instance and you can customize the build or development process in Node.js Runtime. | +| [createRspeedy({ cwd, rspeedyConfig, loadEnv, environment, callerName, })](./rspeedy.createrspeedy.md) | The createRspeedy method can let you create a Rspeedy instance and you can customize the build or development process in Node.js Runtime. | | [defineConfig(config)](./rspeedy.defineconfig.md) | The defineConfig method is a helper function used to get TypeScript intellisense. | | [loadConfig(loadConfigOptions)](./rspeedy.loadconfig.md) | Load the build config by the config path. | | [mergeRspeedyConfig(configs)](./rspeedy.mergerspeedyconfig.md) | Merge multiple Rspeedy configuration objects. | @@ -30,6 +30,7 @@ export default defineConfig({ | Interface | Description | | --- | --- | +| [BuildCache](./rspeedy.buildcache.md) |

**_(BETA)_** Enable or configure persistent build cache.

This feature is experimental and may be changed in the future.

| | [ChunkSplit](./rspeedy.chunksplit.md) | [Performance.chunkSplit](./rspeedy.performance.chunksplit.md) is used to configure the chunk splitting strategy. | | [ChunkSplitBySize](./rspeedy.chunksplitbysize.md) | [Performance.chunkSplit](./rspeedy.performance.chunksplit.md) is used to configure the chunk splitting strategy. | | [ChunkSplitCustom](./rspeedy.chunksplitcustom.md) | [Performance.chunkSplit](./rspeedy.performance.chunksplit.md) is used to configure the chunk splitting strategy. | diff --git a/docs/en/api/rspeedy/rspeedy.performance.buildcache.md b/docs/en/api/rspeedy/rspeedy.performance.buildcache.md new file mode 100644 index 000000000..39e82e478 --- /dev/null +++ b/docs/en/api/rspeedy/rspeedy.performance.buildcache.md @@ -0,0 +1,50 @@ + + +[Home](./index.md) > [@lynx-js/rspeedy](./rspeedy.md) > [Performance](./rspeedy.performance.md) > [buildCache](./rspeedy.performance.buildcache.md) + +## Performance.buildCache property + +> This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Enable or configure persistent build cache. + +This feature is experimental and may be changed in the future. + +**Signature:** + +```typescript +buildCache?: BuildCache | boolean | undefined; +``` + +## Example 1 + +Enable persistent build cache. + +```js +import { defineConfig } from '@lynx-js/rspeedy' + +export default defineConfig({ + performance: { + buildCache: true, + }, +}) +``` + +## Example 2 + +Customize build cache. + +```js +import { defineConfig } from '@lynx-js/rspeedy' + +export default defineConfig({ + performance: { + buildCache: { + cacheDigest: [process.env.SOME_ENV], + buildDependencies: ['postcss.config.js'], + }, + }, +}) +``` + diff --git a/docs/en/api/rspeedy/rspeedy.performance.md b/docs/en/api/rspeedy/rspeedy.performance.md index 80539dca6..b6e77aca3 100644 --- a/docs/en/api/rspeedy/rspeedy.performance.md +++ b/docs/en/api/rspeedy/rspeedy.performance.md @@ -16,6 +16,7 @@ export interface Performance | Property | Modifiers | Type | Description | | --- | --- | --- | --- | +| [buildCache?](./rspeedy.performance.buildcache.md) | | [BuildCache](./rspeedy.buildcache.md) \| boolean \| undefined |

**_(BETA)_** _(Optional)_ Enable or configure persistent build cache.

This feature is experimental and may be changed in the future.

| | [chunkSplit?](./rspeedy.performance.chunksplit.md) | | [ChunkSplit](./rspeedy.chunksplit.md) \| [ChunkSplitBySize](./rspeedy.chunksplitbysize.md) \| [ChunkSplitCustom](./rspeedy.chunksplitcustom.md) \| undefined | _(Optional)_ [Performance.chunkSplit](./rspeedy.performance.chunksplit.md) is used to configure the chunk splitting strategy. | | [printFileSize?](./rspeedy.performance.printfilesize.md) | | PerformanceConfig\['printFileSize'\] \| undefined |

_(Optional)_ Whether to print the file sizes after production build.

[Performance.printFileSize](./rspeedy.performance.printfilesize.md)

See [Rsbuild - performance.printFileSize](https://rsbuild.dev/config/performance/print-file-size) for details.

| | [profile?](./rspeedy.performance.profile.md) | | boolean \| undefined | _(Optional)_ Whether capture timing information in the build time and the runtime, the same as the [profile](https://rspack.dev/config/other-options#profile) config of Rspack. | diff --git a/docs/en/api/rspeedy/rspeedy.source.entry.md b/docs/en/api/rspeedy/rspeedy.source.entry.md index 1281dc525..3513381a3 100644 --- a/docs/en/api/rspeedy/rspeedy.source.entry.md +++ b/docs/en/api/rspeedy/rspeedy.source.entry.md @@ -23,7 +23,9 @@ If no value is provided, the default value `'./src/index.js'` will be used. ```js import { defineConfig } from '@lynx-js/rspeedy' export default defineConfig({ - entry: './src/pages/main/index.js', + source: { + entry: './src/pages/main/index.js', + }, }) ``` @@ -34,7 +36,9 @@ export default defineConfig({ ```js import { defineConfig } from '@lynx-js/rspeedy' export default defineConfig({ - entry: ['./src/prefetch.js', './src/pages/main/index.js'], + source: { + entry: ['./src/prefetch.js', './src/pages/main/index.js'], + }, }) ``` @@ -45,9 +49,11 @@ export default defineConfig({ ```js import { defineConfig } from '@lynx-js/rspeedy' export default defineConfig({ - entry: { - foo: './src/pages/foo/index.js', - bar: ['./src/pages/bar/index.js', './src/post.js'], // multiple entry modules is allowed + source: { + entry: { + foo: './src/pages/foo/index.js', + bar: ['./src/pages/bar/index.js', './src/post.js'], // multiple entry modules is allowed + }, }, }) ``` @@ -59,10 +65,12 @@ export default defineConfig({ ```js import { defineConfig } from '@lynx-js/rspeedy' export default defineConfig({ - entry: { - foo: './src/pages/foo/index.js', - bar: { - import: ['./src/prefetch.js', './src/pages/bar'], + source: { + entry: { + foo: './src/pages/foo/index.js', + bar: { + import: ['./src/prefetch.js', './src/pages/bar'], + }, }, }, }) diff --git a/docs/en/api/rspeedy/rspeedy.source.md b/docs/en/api/rspeedy/rspeedy.source.md index b8670ebf4..8e87a6824 100644 --- a/docs/en/api/rspeedy/rspeedy.source.md +++ b/docs/en/api/rspeedy/rspeedy.source.md @@ -23,6 +23,7 @@ export interface Source | [entry?](./rspeedy.source.entry.md) | | [Entry](./rspeedy.entry.md) \| undefined | _(Optional)_ The [Entry](./rspeedy.entry.md) option is used to set the entry module. | | [exclude?](./rspeedy.source.exclude.md) | | Rspack.RuleSetCondition\[\] \| undefined | _(Optional)_ The source.exclude is used to specify JavaScript files that should be excluded from compilation. | | [include?](./rspeedy.source.include.md) | | Rspack.RuleSetCondition\[\] \| undefined | _(Optional)_ The source.include is used to specify additional JavaScript files that need to be compiled. | +| [preEntry?](./rspeedy.source.preentry.md) | | string \| string\[\] \| undefined | _(Optional)_ Add a script before the entry file of each page. This script will be executed before the page code. It can be used to execute global logics, such as injecting polyfills, setting global styles, etc. | | [transformImport?](./rspeedy.source.transformimport.md) | | [TransformImport](./rspeedy.transformimport.md)\[\] \| undefined | _(Optional)_ The [TransformImport](./rspeedy.transformimport.md) option transforms the import paths to enable modular imports from subpaths of third-party packages, similar to the functionality provided by [babel-plugin-import](https://npmjs.com/package/babel-plugin-import). | | [tsconfigPath?](./rspeedy.source.tsconfigpath.md) | | string \| undefined | _(Optional)_ Configure a custom tsconfig.json file path to use, can be a relative or absolute path. Defaults to be ./tsconfig.json. | diff --git a/docs/en/api/rspeedy/rspeedy.source.preentry.md b/docs/en/api/rspeedy/rspeedy.source.preentry.md new file mode 100644 index 000000000..1b168a970 --- /dev/null +++ b/docs/en/api/rspeedy/rspeedy.source.preentry.md @@ -0,0 +1,31 @@ + + +[Home](./index.md) > [@lynx-js/rspeedy](./rspeedy.md) > [Source](./rspeedy.source.md) > [preEntry](./rspeedy.source.preentry.md) + +## Source.preEntry property + +Add a script before the entry file of each page. This script will be executed before the page code. It can be used to execute global logics, such as injecting polyfills, setting global styles, etc. + +**Signature:** + +```typescript +preEntry?: string | string[] | undefined; +``` + +## Remarks + +See [source.preEntry](https://rsbuild.dev/config/source/pre-entry) for more details. + +## Example + +Relative path will be resolved relative to the project root directory. + +```js +import { defineConfig } from '@lynx-js/rspeedy' +export default defineConfig({ + source: { + preEntry: './src/polyfill.ts', + }, +}) +``` + diff --git a/docs/zh/api/rspeedy/rspeedy.buildcache.builddependencies.md b/docs/zh/api/rspeedy/rspeedy.buildcache.builddependencies.md new file mode 100644 index 000000000..ef905eea8 --- /dev/null +++ b/docs/zh/api/rspeedy/rspeedy.buildcache.builddependencies.md @@ -0,0 +1,47 @@ + + +[Home](./index.md) > [@lynx-js/rspeedy](./rspeedy.md) > [BuildCache](./rspeedy.buildcache.md) > [buildDependencies](./rspeedy.buildcache.builddependencies.md) + +## BuildCache.buildDependencies property + +> This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +An array of files containing build dependencies. Rspack will use the hash of each of these files to invalidate the persistent cache. + +**Signature:** + +```typescript +buildDependencies?: string[] | undefined; +``` + +## Remarks + +Rspeedy will use the following configuration files as the default build dependencies: + +- `package.json` + +- `tsconfig.json` (or `source.tsconfigPath`) + +- `.env`, `.env.*` + +- `tailwindcss.config.*` + +When using Rspeedy CLI, it will also automatically add `lynx.config.js` to the build dependencies. + +## Example + +Add `postcss.config.js` to the build dependencies. + +```js +import { defineConfig } from '@lynx-js/rspeedy' + +export default defineConfig({ + performance: { + buildCache: { + buildDependencies: ['postcss.config.js'], + }, + }, +}) +``` + diff --git a/docs/zh/api/rspeedy/rspeedy.buildcache.cachedigest.md b/docs/zh/api/rspeedy/rspeedy.buildcache.cachedigest.md new file mode 100644 index 000000000..d0213b8a6 --- /dev/null +++ b/docs/zh/api/rspeedy/rspeedy.buildcache.cachedigest.md @@ -0,0 +1,33 @@ + + +[Home](./index.md) > [@lynx-js/rspeedy](./rspeedy.md) > [BuildCache](./rspeedy.buildcache.md) > [cacheDigest](./rspeedy.buildcache.cachedigest.md) + +## BuildCache.cacheDigest property + +> This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Add additional cache digests, the previous build cache will be invalidated when any value in the array changes. + +**Signature:** + +```typescript +cacheDigest?: Array | undefined; +``` + +## Example + +Add `process.env.SOME_ENV` to the cache digest. + +```js +import { defineConfig } from '@lynx-js/rspeedy' + +export default defineConfig({ + performance: { + buildCache: { + cacheDigest: [process.env.SOME_ENV], + }, + }, +}) +``` + diff --git a/docs/zh/api/rspeedy/rspeedy.buildcache.cachedirectory.md b/docs/zh/api/rspeedy/rspeedy.buildcache.cachedirectory.md new file mode 100644 index 000000000..b90764d90 --- /dev/null +++ b/docs/zh/api/rspeedy/rspeedy.buildcache.cachedirectory.md @@ -0,0 +1,16 @@ + + +[Home](./index.md) > [@lynx-js/rspeedy](./rspeedy.md) > [BuildCache](./rspeedy.buildcache.md) > [cacheDirectory](./rspeedy.buildcache.cachedirectory.md) + +## BuildCache.cacheDirectory property + +> This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +The output directory of the cache files. + +**Signature:** + +```typescript +cacheDirectory?: string | undefined; +``` diff --git a/docs/zh/api/rspeedy/rspeedy.buildcache.md b/docs/zh/api/rspeedy/rspeedy.buildcache.md new file mode 100644 index 000000000..655115d75 --- /dev/null +++ b/docs/zh/api/rspeedy/rspeedy.buildcache.md @@ -0,0 +1,27 @@ + + +[Home](./index.md) > [@lynx-js/rspeedy](./rspeedy.md) > [BuildCache](./rspeedy.buildcache.md) + +## BuildCache interface + +> This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Enable or configure persistent build cache. + +This feature is experimental and may be changed in the future. + +**Signature:** + +```typescript +export interface BuildCache +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [buildDependencies?](./rspeedy.buildcache.builddependencies.md) | | string\[\] \| undefined | **_(BETA)_** _(Optional)_ An array of files containing build dependencies. Rspack will use the hash of each of these files to invalidate the persistent cache. | +| [cacheDigest?](./rspeedy.buildcache.cachedigest.md) | | Array<string \| undefined> \| undefined | **_(BETA)_** _(Optional)_ Add additional cache digests, the previous build cache will be invalidated when any value in the array changes. | +| [cacheDirectory?](./rspeedy.buildcache.cachedirectory.md) | | string \| undefined | **_(BETA)_** _(Optional)_ The output directory of the cache files. | + diff --git a/docs/zh/api/rspeedy/rspeedy.createrspeedy.md b/docs/zh/api/rspeedy/rspeedy.createrspeedy.md index ee316316b..a67096af2 100644 --- a/docs/zh/api/rspeedy/rspeedy.createrspeedy.md +++ b/docs/zh/api/rspeedy/rspeedy.createrspeedy.md @@ -9,14 +9,14 @@ The `createRspeedy` method can let you create a Rspeedy instance and you can cus **Signature:** ```typescript -export declare function createRspeedy({ cwd, rspeedyConfig, loadEnv, environment }: CreateRspeedyOptions): Promise; +export declare function createRspeedy({ cwd, rspeedyConfig, loadEnv, environment, callerName, }: CreateRspeedyOptions): Promise; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| { cwd, rspeedyConfig, loadEnv, environment } | [CreateRspeedyOptions](./rspeedy.createrspeedyoptions.md) | | +| { cwd, rspeedyConfig, loadEnv, environment, callerName, } | [CreateRspeedyOptions](./rspeedy.createrspeedyoptions.md) | | **Returns:** diff --git a/docs/zh/api/rspeedy/rspeedy.createrspeedyoptions.callername.md b/docs/zh/api/rspeedy/rspeedy.createrspeedyoptions.callername.md new file mode 100644 index 000000000..8d3ab00e5 --- /dev/null +++ b/docs/zh/api/rspeedy/rspeedy.createrspeedyoptions.callername.md @@ -0,0 +1,43 @@ + + +[Home](./index.md) > [@lynx-js/rspeedy](./rspeedy.md) > [CreateRspeedyOptions](./rspeedy.createrspeedyoptions.md) > [callerName](./rspeedy.createrspeedyoptions.callername.md) + +## CreateRspeedyOptions.callerName property + +The name of the framework or tool that is currently invoking Rsbuild. This allows plugins to tailor their behavior based on the calling context. + +**Signature:** + +```typescript +callerName?: string; +``` + +## Example + +Rsbuild plugins can access this value via `api.context.callerName`. + +```js +export function myPlugin() { + return { + name: 'my-plugin', + setup(api) { + // Log the name of the tool invoking Rsbuild + console.log(`Called by: ${api.context.callerName}`); + + // Conditionally apply plugin logic based on caller + if (api.context.callerName === 'rspeedy') { + api.modifyRsbuildConfig((config) => { + // Apply rspeedy-specific config changes + return config; + }); + } else if (api.context.callerName === 'rslib') { + api.modifyRsbuildConfig((config) => { + // Apply rslib-specific config changes + return config; + }); + } + } + }; +} +``` + diff --git a/docs/zh/api/rspeedy/rspeedy.createrspeedyoptions.md b/docs/zh/api/rspeedy/rspeedy.createrspeedyoptions.md index 6130d1077..e6b53be27 100644 --- a/docs/zh/api/rspeedy/rspeedy.createrspeedyoptions.md +++ b/docs/zh/api/rspeedy/rspeedy.createrspeedyoptions.md @@ -16,6 +16,7 @@ export interface CreateRspeedyOptions | Property | Modifiers | Type | Description | | --- | --- | --- | --- | +| [callerName?](./rspeedy.createrspeedyoptions.callername.md) | | string | _(Optional)_ The name of the framework or tool that is currently invoking Rsbuild. This allows plugins to tailor their behavior based on the calling context. | | [cwd?](./rspeedy.createrspeedyoptions.cwd.md) | | string | _(Optional)_ The root path of the current build. | | [environment?](./rspeedy.createrspeedyoptions.environment.md) | | CreateRsbuildOptions\['environment'\] | _(Optional)_ Only build specified environments. For example, passing ['lynx'] will only build the lynx environment. If not specified or passing an empty array, all environments will be built. | | [loadEnv?](./rspeedy.createrspeedyoptions.loadenv.md) | | CreateRsbuildOptions\['loadEnv'\] | _(Optional)_ Rspeedy automatically loads the .env file by default, utilizing the \[Rsbuild API\](https://rsbuild.dev/api/javascript-api/core\#load-env-variables). 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. | diff --git a/docs/zh/api/rspeedy/rspeedy.md b/docs/zh/api/rspeedy/rspeedy.md index df2ae9fc8..809ae193c 100644 --- a/docs/zh/api/rspeedy/rspeedy.md +++ b/docs/zh/api/rspeedy/rspeedy.md @@ -21,7 +21,7 @@ export default defineConfig({ | Function | Description | | --- | --- | -| [createRspeedy({ cwd, rspeedyConfig, loadEnv, environment })](./rspeedy.createrspeedy.md) | The createRspeedy method can let you create a Rspeedy instance and you can customize the build or development process in Node.js Runtime. | +| [createRspeedy({ cwd, rspeedyConfig, loadEnv, environment, callerName, })](./rspeedy.createrspeedy.md) | The createRspeedy method can let you create a Rspeedy instance and you can customize the build or development process in Node.js Runtime. | | [defineConfig(config)](./rspeedy.defineconfig.md) | The defineConfig method is a helper function used to get TypeScript intellisense. | | [loadConfig(loadConfigOptions)](./rspeedy.loadconfig.md) | Load the build config by the config path. | | [mergeRspeedyConfig(configs)](./rspeedy.mergerspeedyconfig.md) | Merge multiple Rspeedy configuration objects. | @@ -30,6 +30,7 @@ export default defineConfig({ | Interface | Description | | --- | --- | +| [BuildCache](./rspeedy.buildcache.md) |

**_(BETA)_** Enable or configure persistent build cache.

This feature is experimental and may be changed in the future.

| | [ChunkSplit](./rspeedy.chunksplit.md) | [Performance.chunkSplit](./rspeedy.performance.chunksplit.md) is used to configure the chunk splitting strategy. | | [ChunkSplitBySize](./rspeedy.chunksplitbysize.md) | [Performance.chunkSplit](./rspeedy.performance.chunksplit.md) is used to configure the chunk splitting strategy. | | [ChunkSplitCustom](./rspeedy.chunksplitcustom.md) | [Performance.chunkSplit](./rspeedy.performance.chunksplit.md) is used to configure the chunk splitting strategy. | diff --git a/docs/zh/api/rspeedy/rspeedy.performance.buildcache.md b/docs/zh/api/rspeedy/rspeedy.performance.buildcache.md new file mode 100644 index 000000000..39e82e478 --- /dev/null +++ b/docs/zh/api/rspeedy/rspeedy.performance.buildcache.md @@ -0,0 +1,50 @@ + + +[Home](./index.md) > [@lynx-js/rspeedy](./rspeedy.md) > [Performance](./rspeedy.performance.md) > [buildCache](./rspeedy.performance.buildcache.md) + +## Performance.buildCache property + +> This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. +> + +Enable or configure persistent build cache. + +This feature is experimental and may be changed in the future. + +**Signature:** + +```typescript +buildCache?: BuildCache | boolean | undefined; +``` + +## Example 1 + +Enable persistent build cache. + +```js +import { defineConfig } from '@lynx-js/rspeedy' + +export default defineConfig({ + performance: { + buildCache: true, + }, +}) +``` + +## Example 2 + +Customize build cache. + +```js +import { defineConfig } from '@lynx-js/rspeedy' + +export default defineConfig({ + performance: { + buildCache: { + cacheDigest: [process.env.SOME_ENV], + buildDependencies: ['postcss.config.js'], + }, + }, +}) +``` + diff --git a/docs/zh/api/rspeedy/rspeedy.performance.md b/docs/zh/api/rspeedy/rspeedy.performance.md index 80539dca6..b6e77aca3 100644 --- a/docs/zh/api/rspeedy/rspeedy.performance.md +++ b/docs/zh/api/rspeedy/rspeedy.performance.md @@ -16,6 +16,7 @@ export interface Performance | Property | Modifiers | Type | Description | | --- | --- | --- | --- | +| [buildCache?](./rspeedy.performance.buildcache.md) | | [BuildCache](./rspeedy.buildcache.md) \| boolean \| undefined |

**_(BETA)_** _(Optional)_ Enable or configure persistent build cache.

This feature is experimental and may be changed in the future.

| | [chunkSplit?](./rspeedy.performance.chunksplit.md) | | [ChunkSplit](./rspeedy.chunksplit.md) \| [ChunkSplitBySize](./rspeedy.chunksplitbysize.md) \| [ChunkSplitCustom](./rspeedy.chunksplitcustom.md) \| undefined | _(Optional)_ [Performance.chunkSplit](./rspeedy.performance.chunksplit.md) is used to configure the chunk splitting strategy. | | [printFileSize?](./rspeedy.performance.printfilesize.md) | | PerformanceConfig\['printFileSize'\] \| undefined |

_(Optional)_ Whether to print the file sizes after production build.

[Performance.printFileSize](./rspeedy.performance.printfilesize.md)

See [Rsbuild - performance.printFileSize](https://rsbuild.dev/config/performance/print-file-size) for details.

| | [profile?](./rspeedy.performance.profile.md) | | boolean \| undefined | _(Optional)_ Whether capture timing information in the build time and the runtime, the same as the [profile](https://rspack.dev/config/other-options#profile) config of Rspack. | diff --git a/docs/zh/api/rspeedy/rspeedy.source.entry.md b/docs/zh/api/rspeedy/rspeedy.source.entry.md index 1281dc525..3513381a3 100644 --- a/docs/zh/api/rspeedy/rspeedy.source.entry.md +++ b/docs/zh/api/rspeedy/rspeedy.source.entry.md @@ -23,7 +23,9 @@ If no value is provided, the default value `'./src/index.js'` will be used. ```js import { defineConfig } from '@lynx-js/rspeedy' export default defineConfig({ - entry: './src/pages/main/index.js', + source: { + entry: './src/pages/main/index.js', + }, }) ``` @@ -34,7 +36,9 @@ export default defineConfig({ ```js import { defineConfig } from '@lynx-js/rspeedy' export default defineConfig({ - entry: ['./src/prefetch.js', './src/pages/main/index.js'], + source: { + entry: ['./src/prefetch.js', './src/pages/main/index.js'], + }, }) ``` @@ -45,9 +49,11 @@ export default defineConfig({ ```js import { defineConfig } from '@lynx-js/rspeedy' export default defineConfig({ - entry: { - foo: './src/pages/foo/index.js', - bar: ['./src/pages/bar/index.js', './src/post.js'], // multiple entry modules is allowed + source: { + entry: { + foo: './src/pages/foo/index.js', + bar: ['./src/pages/bar/index.js', './src/post.js'], // multiple entry modules is allowed + }, }, }) ``` @@ -59,10 +65,12 @@ export default defineConfig({ ```js import { defineConfig } from '@lynx-js/rspeedy' export default defineConfig({ - entry: { - foo: './src/pages/foo/index.js', - bar: { - import: ['./src/prefetch.js', './src/pages/bar'], + source: { + entry: { + foo: './src/pages/foo/index.js', + bar: { + import: ['./src/prefetch.js', './src/pages/bar'], + }, }, }, }) diff --git a/docs/zh/api/rspeedy/rspeedy.source.md b/docs/zh/api/rspeedy/rspeedy.source.md index b8670ebf4..8e87a6824 100644 --- a/docs/zh/api/rspeedy/rspeedy.source.md +++ b/docs/zh/api/rspeedy/rspeedy.source.md @@ -23,6 +23,7 @@ export interface Source | [entry?](./rspeedy.source.entry.md) | | [Entry](./rspeedy.entry.md) \| undefined | _(Optional)_ The [Entry](./rspeedy.entry.md) option is used to set the entry module. | | [exclude?](./rspeedy.source.exclude.md) | | Rspack.RuleSetCondition\[\] \| undefined | _(Optional)_ The source.exclude is used to specify JavaScript files that should be excluded from compilation. | | [include?](./rspeedy.source.include.md) | | Rspack.RuleSetCondition\[\] \| undefined | _(Optional)_ The source.include is used to specify additional JavaScript files that need to be compiled. | +| [preEntry?](./rspeedy.source.preentry.md) | | string \| string\[\] \| undefined | _(Optional)_ Add a script before the entry file of each page. This script will be executed before the page code. It can be used to execute global logics, such as injecting polyfills, setting global styles, etc. | | [transformImport?](./rspeedy.source.transformimport.md) | | [TransformImport](./rspeedy.transformimport.md)\[\] \| undefined | _(Optional)_ The [TransformImport](./rspeedy.transformimport.md) option transforms the import paths to enable modular imports from subpaths of third-party packages, similar to the functionality provided by [babel-plugin-import](https://npmjs.com/package/babel-plugin-import). | | [tsconfigPath?](./rspeedy.source.tsconfigpath.md) | | string \| undefined | _(Optional)_ Configure a custom tsconfig.json file path to use, can be a relative or absolute path. Defaults to be ./tsconfig.json. | diff --git a/docs/zh/api/rspeedy/rspeedy.source.preentry.md b/docs/zh/api/rspeedy/rspeedy.source.preentry.md new file mode 100644 index 000000000..1b168a970 --- /dev/null +++ b/docs/zh/api/rspeedy/rspeedy.source.preentry.md @@ -0,0 +1,31 @@ + + +[Home](./index.md) > [@lynx-js/rspeedy](./rspeedy.md) > [Source](./rspeedy.source.md) > [preEntry](./rspeedy.source.preentry.md) + +## Source.preEntry property + +Add a script before the entry file of each page. This script will be executed before the page code. It can be used to execute global logics, such as injecting polyfills, setting global styles, etc. + +**Signature:** + +```typescript +preEntry?: string | string[] | undefined; +``` + +## Remarks + +See [source.preEntry](https://rsbuild.dev/config/source/pre-entry) for more details. + +## Example + +Relative path will be resolved relative to the project root directory. + +```js +import { defineConfig } from '@lynx-js/rspeedy' +export default defineConfig({ + source: { + preEntry: './src/polyfill.ts', + }, +}) +``` +