
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
vite-plugin-externals
Advanced tools
use to external resources, like webpack externals, but only use in browser now.
Can be used in production
mode without other rollup
configuration.
but it will not take effect by default in commonjs
, such as ssr
.
npm i vite-plugin-externals -D
Add it to vite.config.js
// vite.config.js
import { viteExternalsPlugin } from 'vite-plugin-externals'
export default {
plugins: [
viteExternalsPlugin({
vue: 'Vue',
react: 'React',
'react-dom': 'ReactDOM',
}),
]
}
transform source code of js file.
// configuration
viteExternalsPlugin({
vue: 'Vue',
}),
// source code
import Vue from 'vue'
// transformed
const Vue = window.Vue
// source code
import { reactive, ref as r } from 'vue'
// transformed
const reactive = window.Vue.reactive
const r = window.Vue.ref
Warning: please use the plugin after converting to JS code, because the plugin only transform JS code. Eg.
import vue from '@vitejs/plugin-vue'
export default {
plugins: [
vue(), // @vitejs/plugin-vue will transofrm SFC to JS code
// It should be under @vitejs/plugin-vue
viteExternalsPlugin({
vue: 'Vue',
}),
]
}
The files in node_modules
are filtered by default, and only transform js/ts/vue/jsx/tsx file.
You can specify the filter
function. Return true
will be transform to external.
viteExternalsPlugin({
vue: 'Vue',
}, {
filter(code, id, ssr) {
// your code
return false
}
}),
set false
, the window
prefix will not be added.
viteExternalsPlugin({
vue: 'Vue',
}, { useWindow: false }),
// source code
import Vue from 'vue'
// transformed, no `const Vue = window.Vue`
const Vue = Vue
FAQs
externals plugin for vite
The npm package vite-plugin-externals receives a total of 31,151 weekly downloads. As such, vite-plugin-externals popularity was classified as popular.
We found that vite-plugin-externals demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.