Without lexical transform, support custom external code
English | 简体中文
-
Like Webpack externals, support browser, Node.js and Electron
-
With out ast analyze, load virtual files by resolveId-hooks -- Real efficient
-
Support customize the code snippets by return string from function -- Real flexible 🎉
npm i vite-plugin-fast-external -D
import external from 'vite-plugin-fast-external';
export default defineConfig({
plugins: [
external({
// Simple example
// By default will generated code -> const Vue = window['Vue']; export { Vue as default }
vue: 'Vue',
// Support nesting module name
// Support custom external code by function
'@namespace/lib-name': () => `
const lib = window.LibName;
export default lib;
export const Message = lib.Message
export const Notification = lib.Notification;
`,
// Load a template file and return Promise<string>
externalId: () => require('fs/promises').readFile('path', 'utf-8'),
// Use in Electron
electron: () => `const { ipcRenderer } = require('electron'); export { ipcRenderer }`,
})
]
})
entries
Record<string, string | ((id: string) => string | Promise<string>)>;