接口: Filename
Filename 决定输出到 Output.distPath 下的 Lynx bundle 文件的名称。
备注
如果传入字符串,它将被用作 Filename.bundle。
属性
assets?
optional assets?: Filename
其他静态资源的名称,不包括上述类型(image、svg、font、html、wasm...)
默认值
'[name].[contenthash:8][ext]'
bundle?
optional bundle?: BundleFilename
bundle 文件的名称。
备注
支持以下占位符:
[name]:入口名称。
[platform]:Rsbuild environment 的名称。
[contenthash]:bundle 内容的 hash。
默认值
'[name].[platform].bundle'
示例
- 在 bundle 文件名中使用 content hash:
import { defineConfig } from '@lynx-js/rspeedy'
export default defineConfig({
output: {
filename: {
bundle: '[name].[contenthash].bundle',
},
},
})
- 在 bundle 文件名中使用指定长度的 content hash:
import { defineConfig } from '@lynx-js/rspeedy'
export default defineConfig({
output: {
filename: {
bundle: '[name].[contenthash:8].bundle',
},
},
})
- 使用函数分别控制主 bundle 和 lazy bundle
(例如将 lazy bundle 输出到另一个目录,并附加 git
commit hash):
import { execSync } from 'node:child_process'
import { defineConfig } from '@lynx-js/rspeedy'
const gitHash = execSync('git rev-parse --short HEAD').toString().trim()
export default defineConfig({
output: {
filename: {
bundle: ({ lazyBundle, platform }) =>
lazyBundle
? `my-lazy-bundles/[name].[fullhash]-${gitHash}.bundle`
: `[name].${platform}.bundle`,
},
},
})
css?
optional css?: Filename
Lynx Default Changed
CSS 文件的名称。
默认值
'[name]/[name].css'
示例
import { defineConfig } from '@lynx-js/rspeedy'
export default defineConfig({
output: {
filename: {
css: (pathData, assetInfo) => {
console.log(pathData); // You can check the contents of pathData here
if (pathData.chunk?.name === 'index') {
return isProd ? '[name].[contenthash:8].css' : '[name].css';
}
return '/some-path/[name].css';
},
},
},
})
font?
optional font?: Filename
字体文件的名称。
默认值
'[name].[contenthash:8][ext]'
image?
optional image?: Filename
非 SVG 图片的名称。
默认值
'[name].[contenthash:8][ext]'
js?
optional js?: Filename
JavaScript 文件的名称。
默认值
开发环境下为 '[name].js',生产环境 web 构建为 '[name].[contenthash:8].js',生产环境 node 构建为 '[name].js'
示例
import { defineConfig } from '@lynx-js/rspeedy'
export default defineConfig({
output: {
filename: {
js: (pathData, assetInfo) => {
console.log(pathData); // You can check the contents of pathData here
if (pathData.chunk?.name === 'index') {
return isProd ? '[name].[contenthash:8].js' : '[name].js';
}
return '/some-path/[name].js';
},
},
},
})
optional media?: Filename
媒体资源(如视频)的名称。
默认值
'[name].[contenthash:8][ext]'
svg?
optional svg?: Filename
SVG 图片的名称。
默认值
'[name].[contenthash:8].svg'
template?
optional template?: string
模板文件的名称。
已被弃用
请使用 Filename.bundle 代替。
默认值
'[name].[platform].bundle'
备注
支持以下占位符:
[name]:入口名称。
[contenthash]:模板的 contenthash。
示例
- 在 bundle 文件名中使用 content hash:
import { defineConfig } from '@lynx-js/rspeedy'
export default defineConfig({
output: {
filename: {
template: '[name].[contenthash].bundle',
},
},
})
- 在 bundle 文件名中使用指定长度的 content hash:
import { defineConfig } from '@lynx-js/rspeedy'
export default defineConfig({
output: {
filename: {
template: '[name].[contenthash:8].bundle',
},
},
})
wasm?
optional wasm?: string
WebAssembly 文件的名称。
默认值
'[contenthash:8].module.wasm'