
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-codegen
Advanced tools
A plugin for Vite (v4 and higher) to generate useful modules at bundle-time.
vite-plugin-codegenA plugin for vite to allow bundle-time asset generation. This can be useful to work efficiently with established conventions and reduce duplication and boilerplate code.
It follows pretty much the parcel-plugin-codegen implementation.
Install the plugin:
npm i vite-plugin-codegen --save-dev
Now in your vite configuration file you can do:
import codegen from 'vite-plugin-codegen';
export default {
// ...
plugins: [codegen()],
};
At this point you can reference a .codegen file in any file, e.g., in a TypeScript asset
import generatedModule from './my.codegen';
Create a .codegen file with the structure:
module.exports = function() {
return `export default function() {}`;
};
You can also use promises in your code generation. As an example, if your .codegen file looks similar to this:
module.exports = function() {
return callSomeApi().then(result => `export default function() { return ${JSON.stringify(result)}; }`);
};
The new asset will be created asynchronously. Furthermore, you can obviously use require or import directly in your generated code. Since the asset will be run through vite like any other asset, you can use this mechanism to include files from a directory without referencing them explicitly:
module.exports = function() {
return `
import { lazy } from 'react';
export default lazy(() => import(${JSON.stringify(filePath)}));
`;
};
This plugin is released using the MIT license. For more information see the LICENSE file.
FAQs
A plugin for Vite (v4 and higher) to generate useful modules at bundle-time.
The npm package vite-plugin-codegen receives a total of 2,220 weekly downloads. As such, vite-plugin-codegen popularity was classified as popular.
We found that vite-plugin-codegen 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.