🍣 A universal bundler plugin which scans modules for global variables and injects import
statements where necessary.
npm i unplugin-inject
Vite
// vite.config.ts
import UnpluginInject from 'unplugin-inject/vite'
export default defineConfig({
plugins: [
UnpluginInject({
/* options */
}),
],
})
Example: playground/
Rollup
// rollup.config.js
import UnpluginInject from 'unplugin-inject/rollup'
export default {
plugins: [
UnpluginInject({
/* options */
}),
],
}
Webpack
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-inject/webpack')({
/* options */
}),
],
}
Nuxt
// nuxt.config.js
export default defineNuxtConfig({
modules: [
[
'unplugin-inject/nuxt',
{
/* options */
},
],
],
})
This module works for both Nuxt 2 and Nuxt Vite
Vue CLI
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-inject/webpack')({
/* options */
}),
],
},
}
esbuild
// esbuild.config.js
import { build } from 'esbuild'
import UnpluginInject from 'unplugin-inject/esbuild'
build({
plugins: [UnpluginInject()],
})
For all options please refer to docs.
This plugin accepts all @rollup/plugin-inject options.