Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/some-swans-stop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@lynx-js/rspeedy": patch
---

Support `output.distPath.*`.

See [Rsbuild - distPath](https://rsbuild.dev/config/output/dist-path) for all available options.
8 changes: 2 additions & 6 deletions packages/rspeedy/core/etc/rspeedy.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
```ts

import type { CreateRsbuildOptions } from '@rsbuild/core';
import type { DistPathConfig } from '@rsbuild/core';
import { logger } from '@rsbuild/core';
import type { PerformanceConfig } from '@rsbuild/core';
import type { RsbuildConfig } from '@rsbuild/core';
Expand Down Expand Up @@ -146,13 +147,8 @@ export interface DevClient {
}

// @public
export interface DistPath {
css?: string | undefined;
cssAsync?: string | undefined;
export interface DistPath extends DistPathConfig {
intermediate?: string | undefined;
js?: string | undefined;
jsAsync?: string | undefined;
root?: string | undefined;
}

// @public
Expand Down
59 changes: 3 additions & 56 deletions packages/rspeedy/core/src/config/output/dist-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,14 @@
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.

import type { DistPathConfig } from '@rsbuild/core'

/**
* {@inheritdoc Output.distPath}
*
* @public
*/
export interface DistPath {
/**
* The root directory of all output files.
*
* @remarks
*
* Default value:
*
* - `'dist'`
*/
root?: string | undefined

/**
* The output directory of CSS style files.
*
* @remarks
*
* Default value:
*
* - The same as {@link DistPath.intermediate}
*/
css?: string | undefined

/**
* The output directory of async JavaScript files.
*
* @remarks
*
* Default value:
*
* - The `async` subdirectory of {@link DistPath.css}.
*/
cssAsync?: string | undefined

export interface DistPath extends DistPathConfig {
/**
* The output directory of the intermediate files.
*
Expand All @@ -51,28 +20,6 @@ export interface DistPath {
* - `'.rspeedy'`
*/
intermediate?: string | undefined

/**
* The output directory of JavaScript files.
*
* @remarks
*
* Default value:
*
* - `'static/js'`
*/
js?: string | undefined

/**
* The output directory of async JavaScript files.
*
* @remarks
*
* Default value:
*
* - The `async` subdirectory of {@link DistPath.js}.
*/
jsAsync?: string | undefined
}

export const DEFAULT_DIST_PATH_INTERMEDIATE = '.rspeedy'
6 changes: 5 additions & 1 deletion packages/rspeedy/core/src/config/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface Output {
*
* By default, if the output directory is a subdirectory of the project root path, Rspeedy will automatically clean all files in the build directory.
*
* When {@link DistPath.root | output.distPath.root} is an external directory or the same as the project root directory, `cleanDistPath` is not enabled by default to prevent accidental deletion of files from other directories.
* When {@link https://rsbuild.dev/config/output/dist-path#root-directory | output.distPath.root} is an external directory or the same as the project root directory, `cleanDistPath` is not enabled by default to prevent accidental deletion of files from other directories.
*
* @example
*
Expand Down Expand Up @@ -213,6 +213,10 @@ export interface Output {
/**
* Set the directory of the dist files.
*
* @remarks
*
* More options can be found at {@link https://rsbuild.dev/config/output/dist-path | Rsbuild - distPath}.
*
* @example
*
* Use `output` instead of `dist`(the default value):
Expand Down
30 changes: 30 additions & 0 deletions packages/rspeedy/core/test/config/output.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,36 @@ describe('Config - Output', () => {
root: 'foo',
},
})

assertType<Output>({
distPath: {
intermediate: 'foo',
},
})

assertType<Output>({
distPath: {
css: 'foo',
},
})

assertType<Output>({
distPath: {
cssAsync: 'foo',
},
})

assertType<Output>({
distPath: {
image: 'foo',
},
})

assertType<Output>({
distPath: {
font: 'foo',
},
})
})

test('output.filename', () => {
Expand Down
16 changes: 16 additions & 0 deletions packages/rspeedy/core/test/config/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,12 @@ describe('Config Validation', () => {
{ cleanDistPath: false },
{ distPath: {} },
{ distPath: { root: 'root' } },
{ distPath: { css: 'css' } },
{ distPath: { cssAsync: 'cssAsync' } },
{ distPath: { assets: 'assets' } },
{ distPath: { image: 'image' } },
{ distPath: { font: 'font' } },
{ distPath: { svg: 'svg' } },
{ legalComments: 'inline' },
{ legalComments: 'none' },
{ legalComments: 'linked' },
Expand Down Expand Up @@ -1081,6 +1087,16 @@ describe('Config Validation', () => {
]
`)

expect(() =>
validate({ output: { distPath: { nonExistent: 'nonExistent' } } })
)
.toThrowErrorMatchingInlineSnapshot(`
[Error: Invalid configuration.

Unknown property: \`$input.output.distPath.nonExistent\` in configuration
]
`)

expect(() => validate({ output: { legalComments: [null] } }))
.toThrowErrorMatchingInlineSnapshot(`
[Error: Invalid configuration.
Expand Down
Loading