External links plugin which supports ESM and UMD for vite.
Installations
npm install vite-plugin-externals-extension
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
14.19.0
NPM Version
6.14.16
Contributors
Unable to fetch Contributors
Languages
JavaScript (44.34%)
TypeScript (30.37%)
Makefile (19.74%)
Shell (5.55%)
Developer
XiSenao
Download Statistics
Total Downloads
2,606
Last Day
1
Last Week
8
Last Month
29
Last Year
476
GitHub Statistics
7 Stars
29 Commits
1 Forks
1 Watching
2 Branches
1 Contributors
Bundle Size
1.40 kB
Minified
719.00 B
Minified + Gzipped
Package Meta Information
Latest Version
0.0.7
Package Id
vite-plugin-externals-extension@0.0.7
Unpacked Size
21.70 kB
Size
5.33 kB
File Count
8
NPM Version
6.14.16
Node Version
14.19.0
Total Downloads
Cumulative downloads
Total Downloads
2,606
Last day
-50%
1
Compared to previous day
Last week
-38.5%
8
Compared to previous week
Last month
-6.5%
29
Compared to previous month
Last year
-67.3%
476
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
English | 简体中文
vite-plugin-externals-extension
A Vite/Rollup
plugin which support external link.
Inspired by Webpack. Support for vite
versions including 2.x
and 3.x
, enjoy!
Install
1pnpm install vite-plugin-externals-extension -D
or
1yarn add vite-plugin-externals-extension -D
Usage
Configure plugin like the following example to take effect without modifying any other information. support configuration links including CJS
and ESM
( recommended skypack links).
1// vite.config.ts 2 3import { defineConfig } from 'vite' 4import react from '@vitejs/plugin-react' 5import { compatLowVersion, externalsExtension } from 'vite-plugin-externals-extension' 6 7export default defineConfig({ 8 plugins: [ 9 react(), 10 externalsExtension({ 11 htm: { 12 url: 'https://cdn.skypack.dev/htm' 13 }, 14 lodash: { 15 url: 'https://cdn.skypack.dev/lodash', 16 }, 17 redux: { 18 getter: (window) => { 19 return window.Redux; 20 }, 21 url: 'https://cdn.bootcdn.net/ajax/libs/redux/4.2.0/redux.min.js' 22 }, 23 react: { 24 url: 'https://cdn.skypack.dev/pin/react@v17.0.1-yH0aYV1FOvoIPeKBbHxg/mode=imports/optimized/react.js', 25 } 26 }) 27 ], 28 // The vite version above 2.2.0 does not require additional injection of "external". 29 build: { 30 rollupOptions: { 31 external: await compatLowVersion() 32 } 33 } 34}) 35
⚠️ Note:
- Considering the type dependency of
ts
on dependent modules and thehidden injection
of sub-dependent modules, the modules that the project depends still need to be installed, but only need to install `dev' dependencies, which will not affect the package size at the time of production. - For the dependent
vite
version in the2.0.0
~2.2.0
interval, becauseasync plugin config
is not supported,external
needs to be added manually. Just inject the following code:
1 { 2 build: { 3 rollupOptions: { 4 external: await compatLowVersion() 5 } 6 } 7 }
Configuration
The configuration type of plugin interface is as follows. The usage is a little similar to webpack
, it may be clear at a glance through the above examples.
1interface ExternalExtensionType { 2 [key: string]: { 3 getter?: string | ((window: any) => any); 4 url: string | (() => Promise<string>); 5 } 6}
⚠️ Note:
getter
is an optional attribute which is no need to configure getter
hooks when using ESM
links, which is created for adapt to different CJS
packages.
url
is a required option to configure the dependent external links you need. If you need asynchronous link need, also suits your appetite.
Example projects
You can use the example v2.x or the example v3.x in the project to make a demonstration or debug according to your needs.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No security vulnerabilities found.