
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
vite-plugin-import-context
Advanced tools
A dynamic introduction plugin based on vite.Support dynamic import
English | 中文
A dynamic import plugin based on vite.Support dynamic import
node version: >=12.0.0
vite version: >=2.0.0-beta.12
yarn add vite-plugin-import-context -D or npm i vite-plugin-import-context -D
Run Example
cd ./examples
yarn install
yarn serve
import { UserConfigExport } from 'vite';
import vue from '@vitejs/plugin-vue';
import dynamicImport from '../src/index';
export default (): UserConfigExport => {
return {
plugins: [vue(), dynamicImport(/*options*/)],
};
};
ts development environment. Then add the type to tsconfig.json. The corresponding type definition has been configured{
"compilerOptions": {
"types": ["vite-plugin-import-context/client"]
}
}
| param | type | default | description |
|---|---|---|---|
| include | string / RegExp / (string / RegExp)[] / null / undefined | ['**/*.js', '**/*.ts', '**/*.tsx', '**/*.jsx'] | Code directory and file format to be converted |
| exclude | string / RegExp / (string / RegExp)[] / null / undefined | 'node_modules/**' | Excluded files/folders |
In the code, if the keyword function importContext appears, it will be transformed by the plugin.
Please ensure that there are no custom importContext functions or variables in your own code
This example is non-dynamic import. And no deep recursion
// xxx.ts
const nextMainModule = importContext({
dir: './',
deep: false,
regexp: /\.ts$/,
dynamicImport: false,
ignoreCurrentFile: true,
});
nextMainModule.keys().forEach((key) => {
console.log('nextMain=>', nextMainModule(key));
});
It can be matched according to the alias of vite
// xxx.ts
const aliasModule = importContext({
dir: '/@/views',
deep: true,
regexp: /\.ts$/,
});
aliasModule.keys().forEach((key) => {
console.log('aliasModule=>', aliasModule(key));
});
This example is non-dynamic import. And deep recursion
// xxx.ts
const nextMainModule = importContext({
dir: './',
deep: true,
regexp: /\.ts$/,
dynamicImport: false,
ignoreCurrentFile: true,
});
nextMainModule.keys().forEach((key) => {
console.log('nextMain=>', nextMainModule(key));
});
This example is import dynamically. And deep recursion
const dynamicModule = importContext({
dir: './',
deep: true,
regexp: /\.ts$/,
dynamicImport: true,
});
dynamicModule.keys().forEach((key: string) => {
console.log('dynamicModule=>', dynamicModule(key));
dynamicModule(key)().then((res) => {
console.log('======================');
console.log('dynamicModuleRes=>', res);
console.log('======================');
});
});
deep: false, regexp: /.ts$/, dynamicImport: false, ignoreCurrentFile: true,
| param | type | default | description |
|---|---|---|---|
| dir | string | ./ | File path to be imported, support alias |
| deep | boolean | false | Whether to introduce deeply |
| enabled | boolean | true | Whether to convert the code, an empty function will be returned after closing |
| deep | boolean | false | Whether to introduce deeply |
| regexp | regexp | /^\.\// | File matching regular |
| dynamicImport | boolean | false | Whether to enable dynamic import |
| ext | boolean | true | Whether the key value has a suffix |
| ignoreCurrentFile | boolean | true | Whether to ignore the current file. If dir='./', It will import itself, this configuration can ignore the import of itself |
MIT
FAQs
A dynamic introduction plugin based on vite.Support dynamic import
The npm package vite-plugin-import-context receives a total of 150 weekly downloads. As such, vite-plugin-import-context popularity was classified as not popular.
We found that vite-plugin-import-context 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.