Skip to content

Commit f17e19a

Browse files
清尘yyx990803patak-dev
authored
feat: parameter settings when packaging the library (#2750)
Co-authored-by: Evan You <[email protected]> Co-authored-by: patak <[email protected]>
1 parent daf7838 commit f17e19a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

docs/config/index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,10 @@ export default async ({ command, mode }) => {
502502

503503
### build.lib
504504

505-
- **Type:** `{ entry: string, name?: string, formats?: ('es' | 'cjs' | 'umd' | 'iife')[] }`
505+
- **Type:** `{ entry: string, name?: string, formats?: ('es' | 'cjs' | 'umd' | 'iife')[], fileName?: string }`
506506
- **Related:** [Library Mode](/guide/build#library-mode)
507507

508-
Build as a library. `entry` is required since the library cannot use HTML as entry. `name` is the exposed global variable and is required when `formats` includes `'umd'` or `'iife'`. Default `formats` are `['es', 'umd']`.
508+
Build as a library. `entry` is required since the library cannot use HTML as entry. `name` is the exposed global variable and is required when `formats` includes `'umd'` or `'iife'`. Default `formats` are `['es', 'umd']`. `fileName` is the name of the package file output, default `fileName` is the name option of package.json
509509

510510
### build.manifest
511511

packages/vite/src/node/build.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ export interface LibraryOptions {
190190
entry: string
191191
name?: string
192192
formats?: LibraryFormats[]
193+
fileName?: string
193194
}
194195

195196
export type LibraryFormats = 'es' | 'cjs' | 'umd' | 'iife'
@@ -405,7 +406,7 @@ async function doBuild(
405406
entryFileNames: ssr
406407
? `[name].js`
407408
: libOptions
408-
? `${pkgName}.${output.format || `es`}.js`
409+
? `${libOptions.fileName || pkgName}.${output.format || `es`}.js`
409410
: path.posix.join(options.assetsDir, `[name].[hash].js`),
410411
chunkFileNames: libOptions
411412
? `[name].js`

0 commit comments

Comments
 (0)