Skip to content

Commit

Permalink
feat: parameter settings when packaging the library (#2750)
Browse files Browse the repository at this point in the history
Co-authored-by: Evan You <yyx990803@gmail.com>
Co-authored-by: patak <matias.capeletto@gmail.com>
  • Loading branch information
3 people committed Apr 10, 2021
1 parent daf7838 commit f17e19a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,10 @@ export default async ({ command, mode }) => {

### build.lib

- **Type:** `{ entry: string, name?: string, formats?: ('es' | 'cjs' | 'umd' | 'iife')[] }`
- **Type:** `{ entry: string, name?: string, formats?: ('es' | 'cjs' | 'umd' | 'iife')[], fileName?: 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']`.
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.manifest

Expand Down
3 changes: 2 additions & 1 deletion packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export interface LibraryOptions {
entry: string
name?: string
formats?: LibraryFormats[]
fileName?: string
}

export type LibraryFormats = 'es' | 'cjs' | 'umd' | 'iife'
Expand Down Expand Up @@ -405,7 +406,7 @@ async function doBuild(
entryFileNames: ssr
? `[name].js`
: libOptions
? `${pkgName}.${output.format || `es`}.js`
? `${libOptions.fileName || pkgName}.${output.format || `es`}.js`
: path.posix.join(options.assetsDir, `[name].[hash].js`),
chunkFileNames: libOptions
? `[name].js`
Expand Down

0 comments on commit f17e19a

Please sign in to comment.