Skip to content

Commit

Permalink
feat: allow passing options to rollupjs dynamic import vars plugin (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Petersen authored Jun 29, 2021
1 parent b3a2139 commit 5507b4c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
6 changes: 6 additions & 0 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,12 @@ createServer()

Options to pass on to [@rollup/plugin-commonjs](https://github.com/rollup/plugins/tree/master/packages/commonjs).

### build.dynamicImportVarsOptions

- **Type:** [`RollupDynamicImportVarsOptions`](https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#options)

Options to pass on to [@rollup/plugin-dynamic-import-vars](https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars).

### build.lib

- **Type:** `{ entry: string, name?: string, formats?: ('es' | 'cjs' | 'umd' | 'iife')[], fileName?: string }`
Expand Down
15 changes: 11 additions & 4 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { manifestPlugin } from './plugins/manifest'
import commonjsPlugin from '@rollup/plugin-commonjs'
import { RollupCommonJSOptions } from 'types/commonjs'
import dynamicImportVars from '@rollup/plugin-dynamic-import-vars'
import { RollupDynamicImportVarsOptions } from 'types/dynamicImportVars'
import { Logger } from './logger'
import { TransformOptions } from 'esbuild'
import { CleanCSS } from 'types/clean-css'
Expand Down Expand Up @@ -126,6 +127,10 @@ export interface BuildOptions {
* Options to pass on to `@rollup/plugin-commonjs`
*/
commonjsOptions?: RollupCommonJSOptions
/**
* Options to pass on to `@rollup/plugin-dynamic-import-vars`
*/
dynamicImportVarsOptions?: RollupDynamicImportVarsOptions
/**
* Whether to write bundle to disk
* @default true
Expand Down Expand Up @@ -215,6 +220,11 @@ export function resolveBuildOptions(raw?: BuildOptions): ResolvedBuildOptions {
extensions: ['.js', '.cjs'],
...raw?.commonjsOptions
},
dynamicImportVarsOptions: {
warnOnError: true,
exclude: [/node_modules/],
...raw?.dynamicImportVarsOptions
},
minify: raw?.ssr ? false : 'terser',
terserOptions: {},
cleanCssOptions: {},
Expand Down Expand Up @@ -267,10 +277,7 @@ export function resolveBuildPlugins(config: ResolvedConfig): {
...options.commonjsOptions
}),
dataURIPlugin(),
dynamicImportVars({
warnOnError: true,
exclude: [/node_modules/]
}),
dynamicImportVars(options.dynamicImportVarsOptions),
assetImportMetaUrlPlugin(config),
...(options.rollupOptions.plugins
? (options.rollupOptions.plugins.filter((p) => !!p) as Plugin[])
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,4 @@ export type { FSWatcher, WatchOptions } from 'types/chokidar'
export type { Terser } from 'types/terser'
export type { CleanCSS } from 'types/clean-css'
export type { RollupCommonJSOptions } from 'types/commonjs'
export type { RollupDynamicImportVarsOptions } from 'types/dynamicImportVars'
17 changes: 17 additions & 0 deletions packages/vite/types/dynamicImportVars.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export interface RollupDynamicImportVarsOptions {
/**
* Files to include in this plugin (default all).
* @default []
*/
include?: string | RegExp | (string | RegExp)[]
/**
* Files to exclude in this plugin (default none).
* @default []
*/
exclude?: string | RegExp | (string | RegExp)[]
/**
* By default, the plugin quits the build process when it encounters an error. If you set this option to true, it will throw a warning instead and leave the code untouched.
* @default false
*/
warnOnError?: boolean
}

0 comments on commit 5507b4c

Please sign in to comment.