vite-plugin-fast-external
Tiny and fast vite external plugin, without lexical transform.
Installation
npm i -D vite-plugin-fast-external
Usage
import fastExternal from 'vite-plugin-fast-external';
export default defineConfig({
plugins: [
fastExternal({
vue: 'Vue',
'@scope/name': () => `const Lib = window.LibraryName; export default Lib;`,
})
]
})
Options define
export type fastExternal = (
externals: Record<string, string | (() => string)>,
options?: {
/**
* @default 'esm'
* esm will generate code -> const vue = window['Vue']; export { vue as default }
* cjs will generate code -> const vue = window['Vue']; module.exports = vue;
*/
format: 'esm' | 'cjs'
}
) => VitePlugin
How to work
- External-module will be generated code into
node_modules/.vite-plugin-fast-external/vue.js
- Append an external-module alias
{
resolve: {
alias: [
{
find: 'vue',
replacement: 'User/work-directory/node_modules/.vite-plugin-fast-external/vue.js',
},
],
},
}