Skip to content

Latest commit

 

History

History
 
 

fast-external

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

vite-plugin-fast-external

npm package
NPM version NPM Downloads

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 🎉

Install

npm i vite-plugin-fast-external -D

Usage

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 }`,
    })
  ]
})

API

external(entries)

entries

Record<string, string | ((id: string) => string | Promise<string>)>;