Skip to content

Commit

Permalink
docs: improve output.copy examples (#2581)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Jun 12, 2024
1 parent 4348c25 commit acf0b54
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 9 deletions.
18 changes: 17 additions & 1 deletion e2e/cases/output/copy/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,26 @@ test('should copy asset to dist folder correctly', async () => {
distPath: {
root: 'dist-1',
},
copy: [{ from: '../../../assets', to: '' }],
copy: [{ from: '../../../assets' }],
},
},
});

expect(fse.existsSync(join(__dirname, 'dist-1/icon.png'))).toBeTruthy();
});

test('should copy asset to dist sub-folder correctly', async () => {
await build({
cwd: __dirname,
rsbuildConfig: {
output: {
distPath: {
root: 'dist-1',
},
copy: [{ from: '../../../assets', to: 'foo' }],
},
},
});

expect(fse.existsSync(join(__dirname, 'dist-1/foo/icon.png'))).toBeTruthy();
});
26 changes: 22 additions & 4 deletions website/docs/en/config/output/copy.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,34 @@
- **Type:** `CopyPluginOptions | CopyPluginOptions['patterns']`
- **Default:** `undefined`

Copies the specified file or directory to the dist directory.
Copies the specified file or directory to the dist directory, implemented based on [rspack.CopyRspackPlugin](https://rspack.dev/plugins/rspack/copy-rspack-plugin).

For example, copy the files under `src/assets` to the dist directory:
> Please refer to the configuration options here: [rspack.CopyRspackPlugin](https://rspack.dev/plugins/rspack/copy-rspack-plugin).
## Example

Copy files from `./src/assets` to the `./dist` directory:

```js
export default {
output: {
copy: [{ from: './src/assets', to: '' }],
copy: [
// `./src/assets/image.png` -> `./dist/image.png`
{ from: './src/assets' },
],
},
};
```

For more detailed configuration, please refer to: [copy-webpack-plugin](https://github.com/webpack-contrib/copy-webpack-plugin).
Copy files from `./src/assets` to the `./dist/assets` directory:

```js
export default {
output: {
copy: [
// `./src/assets/image.png` -> `./dist/assets/image.png`
{ from: './src/assets', to: 'assets' },
],
},
};
```
26 changes: 22 additions & 4 deletions website/docs/zh/config/output/copy.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,34 @@
- **类型:** `CopyPluginOptions | CopyPluginOptions['patterns']`
- **默认值:** `undefined`

将指定的文件或目录拷贝到构建输出目录中。
将指定的文件或目录拷贝到构建输出目录中,基于 [rspack.CopyRspackPlugin](https://rspack.dev/zh/plugins/rspack/copy-rspack-plugin) 实现

例如,将 `src/assets` 下的文件直接拷贝到 dist 目录:
> 配置项请参考:[rspack.CopyRspackPlugin](https://rspack.dev/zh/plugins/rspack/copy-rspack-plugin)
## 示例

`./src/assets` 下的文件拷贝到 `./dist` 目录:

```js
export default {
output: {
copy: [{ from: './src/assets', to: '' }],
copy: [
// `./src/assets/image.png` -> `./dist/image.png`
{ from: './src/assets' },
],
},
};
```

更详细的配置项请参考:[copy-webpack-plugin](https://github.com/webpack-contrib/copy-webpack-plugin) 文档。
`./src/assets` 下的文件拷贝到 `./dist/assets` 目录:

```js
export default {
output: {
copy: [
// `./src/assets/image.png` -> `./dist/assets/image.png`
{ from: './src/assets', to: 'assets' },
],
},
};
```

0 comments on commit acf0b54

Please sign in to comment.