Socket
Socket
Sign inDemoInstall

vite-plugin-fast-external

Package Overview
Dependencies
0
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vite-plugin-fast-external

Without lexical transform, support custom external code.


Version published
Maintainers
1
Install size
32.9 kB
Created

Readme

Source

vite-plugin-fast-external

npm package
NPM version NPM Downloads

🚀 High performance without lexical transform
🌱 Support custom external code 📦 Built in Vue, React, Antd, Element and others, Out of the box

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 {
  plugins: [
    external({
      vue: 'Vue',
    }),
  ],
}
Builtins

You can easily use some builtin modules

import external from 'vite-plugin-fast-external';
import {
  antd_vue_v1,
  antd_vue_v3,
  antd_v4,
  element_plus,
  element_ui,
  react_dom_v17,
  react_dom_v18,
  react_v17,
  react_v18,
  vue_v2,
  vue_v3,
} from 'vite-plugin-fast-external/presets';

export default {
  plugins: [
    external({
      'ant-design-vue': antd_vue_v3,
      antd: antd_v4,
      'element-plus': element_plus,
      'element-ui': element_ui,
      'react-dom': react_dom_v18,
      react: react_v18,
      vue: vue_v3,
    }),
  ],
}
Customize (Advance)

Support custom external code by function

external({
  module: () => `
    const M = window.Module;
    const D = M.default || M;
    export { D as default };
    export const member1 = M.member1;
    // other members...
  `,
})
Load a file

Support nested module id, support return Promise

resolve({
  'path/filename': () => require('fs/promises').readFile('path', 'utf-8'),
})

API

external(entries)

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

How to work

In fact, the plugin will intercept your module import and return the specified code snippet
Let's use external({ vue: 'Vue' }) as an example, this will get the below code

const M = window['Vue']; export { M as default }

Keywords

FAQs

Last updated on 16 Apr 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc