Skip to content

Commit

Permalink
feat(vite): update LibraryOptions and add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gobeli committed Jun 14, 2021
1 parent 6ae0abd commit 36fabe7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/config/index.md
Expand Up @@ -602,10 +602,10 @@ createServer()

### build.lib

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

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
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, it can also be defined as function taking the `format` as an argument.

### build.manifest

Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/build.ts
Expand Up @@ -193,7 +193,7 @@ export interface LibraryOptions {
entry: string
name?: string
formats?: LibraryFormats[]
fileName?: string | ((format?: ModuleFormat) => string)
fileName?: string | ((format: ModuleFormat) => string)
}

export type LibraryFormats = 'es' | 'cjs' | 'umd' | 'iife'
Expand Down Expand Up @@ -619,7 +619,7 @@ export function resolveLibFilename(
format: ModuleFormat | undefined,
pkgName: string
): string {
return typeof libOptions.fileName === 'function'
return typeof libOptions.fileName === 'function' && format
? libOptions.fileName(format)
: `${libOptions.fileName || pkgName}.${format || `es`}.js`
}
Expand Down

0 comments on commit 36fabe7

Please sign in to comment.