Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
unplugin-auto-import
Advanced tools
unplugin-auto-import is a powerful tool for automatically importing functions, components, and other modules in your JavaScript or TypeScript projects. It helps to reduce boilerplate code and improve development efficiency by eliminating the need to manually import frequently used modules.
Automatic Import of Functions
Automatically imports functions from specified libraries (e.g., Vue and Vue Router) without needing to manually import them in each file.
module.exports = {
plugins: [
require('unplugin-auto-import/webpack')({
imports: ['vue', 'vue-router'],
}),
],
};
Custom Imports
Allows you to specify custom imports from libraries like Lodash, so you can use functions like debounce and throttle without manual imports.
module.exports = {
plugins: [
require('unplugin-auto-import/webpack')({
imports: [
{
'lodash': [
'debounce',
'throttle'
]
}
],
}),
],
};
TypeScript Support
Generates TypeScript declaration files for the auto-imported modules, ensuring type safety and better development experience.
module.exports = {
plugins: [
require('unplugin-auto-import/webpack')({
dts: true,
}),
],
};
ESLint Integration
Integrates with ESLint to ensure that auto-imported modules are recognized and do not trigger linting errors.
module.exports = {
plugins: [
require('unplugin-auto-import/webpack')({
eslintrc: {
enabled: true,
},
}),
],
};
babel-plugin-auto-import is a Babel plugin that automatically imports specified modules when they are used in your code. It is similar to unplugin-auto-import but is specifically designed to work with Babel, making it a good choice for projects that already use Babel for transpilation.
eslint-plugin-import is an ESLint plugin that helps manage and validate import statements in your code. While it does not automatically import modules, it provides rules to ensure that imports are correctly used and can help prevent common issues related to imports.
Auto import APIs on-demand for Vite, Webpack and Rollup. With TypeScript support. Powered by unplugin.
<script setup>
import { ref, computed } from 'vue'
const count = ref(0)
const doubled = computed(() => count.value * 2)
</script>
to
<script setup>
const count = ref(0)
const doubled = computed(() => count.value * 2)
</script>
import { useState } from 'react'
export function Counter() {
const [count, setCount] = useState(0)
return <div>{ count }</div>
}
to
export function Counter() {
const [count, setCount] = useState(0)
return <div>{ count }</div>
}
...and so on.
npm i -D unplugin-auto-import
// vite.config.ts
import AutoImport from 'unplugin-auto-import/vite'
export default defineConfig({
plugins: [
AutoImport({ /* options */ }),
],
})
Example: playground/
// rollup.config.js
import AutoImport from 'unplugin-auto-import/rollup'
export default {
plugins: [
AutoImport({ /* options */ }),
// other plugins
],
}
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-auto-import/webpack')({ /* options */ })
]
}
// nuxt.config.js
export default {
buildModules: [
['unplugin-auto-import/nuxt', { /* options */ }],
],
}
This module works for both Nuxt 2 and Nuxt Vite
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-auto-import/webpack')({ /* options */ }),
],
},
}
AutoImport({
// targets to transform
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue\??/, // .vue
],
// global imports to register
imports: [
// presets
'vue',
'vue-router',
// custom
{
'@vueuse/core': [
'useMouse'
],
'[package-name]': [
'[import-names]',
// alias
['[from]', '[alias]']
]
}
],
// custom resolvers
// see https://github.com/antfu/unplugin-auto-import/pull/23/
resolvers: [
/* ... */
]
})
Refer to the type definitions for more options.
See src/presets.
vue-global-api
You can think this plugin as a successor of vue-global-api
, which offers much more flexibility and it's no longer bound to Vue exclusively. Now you can use it with any libraries you want (e.g. React).
vue-global-api
is pure runtime) - but hey, we have supported quite a few of them already!MIT License © 2021 Anthony Fu
FAQs
Register global imports on demand for Vite and Webpack
The npm package unplugin-auto-import receives a total of 125,556 weekly downloads. As such, unplugin-auto-import popularity was classified as popular.
We found that unplugin-auto-import demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.