vite-plugin-fast-external
Tiny and fast vite external plugin, without lexical transform.
Installation
npm install vite-plugin-fast-external --save-dev
Usage
import fastExternal from 'vite-plugin-fast-external';
export default defineConfig({
plugins: [
fastExternal({
vue: 'Vue',
})
]
});
Definition
export type fastExternal = (
externals: Record<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
-
Generate ESModule code into node_modules/.vite-plugin-fast-external/xxxx.js
- eg:
import Vue from 'vue'
const vue = window['Vue']; export { vue as default }
-
node_modules/.vite-plugin-fast-external/xxxx.js
will be return when vite load hooks - eg:
{
name: 'vite-plugin-fast-external',
load(id) {
if (id.includes('node_modules/.vite-plugin-fast-external')) {
return fs.readFileSync(externalFilename, 'utf8')
}
},
},
TODO