From 36fabe73adb04d15d2b03fb805d6959ab7ef8fd4 Mon Sep 17 00:00:00 2001 From: Etienne Gobeli Date: Mon, 14 Jun 2021 08:35:45 +0200 Subject: [PATCH] feat(vite): update LibraryOptions and add docs --- docs/config/index.md | 4 ++-- packages/vite/src/node/build.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 6c6370fb0c8dbf..d65c49dd6567d9 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -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 diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 372f636b363359..120cb4a87445ab 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -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' @@ -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` }