A Vite plugin that automatically updates your package.json exports map after a build.
pnpm add -D vite-plugin-exports-updaterAdd the plugin to your vite.config.ts:
import { defineConfig } from "vite";
import exportsUpdater from "vite-plugin-exports-updater";
export default defineConfig({
plugins: [exportsUpdater()],
});Now, when you run vite build, the plugin will automatically update the exports map in your package.json to reflect the generated files in your dist directory.
You can pass an options object to the exportsUpdater plugin to customize its behavior.
import { defineConfig } from 'vite';
import exportsUpdater from 'vite-plugin-exports-updater';
export default defineConfig({
plugins: [
exportsUpdater({
entryPointExtensions: ['.js', '.ts', '.vue'], // default: ['.js', '.cjs', '.mjs', '.d.ts']
// To disable CSS handling completely
// css: false,
// To customize CSS handling
css: {
alias: './style.css', // default: './style.css' - The alias for the main CSS file. Set to `false` to disable the alias.
extensions: ['.css', '.scss'], // default: ['.css']
},
}),
],
});entryPointExtensions:string[](default:['.js', '.cjs', '.mjs', '.d.ts'])- An array of file extensions to be treated as entry points.
css:false | { alias?: string | false, extensions?: string[] }(default:{ alias: './style.css', extensions: ['.css'] })- To disable CSS handling entirely, set this option to
false. - To configure CSS handling, provide an object.
- To disable CSS handling entirely, set this option to
css.alias:string | false(default:'./style.css')- Specifies the alias for the main CSS entry point.
- If a
stringis provided (e.g.,'./my-styles.css'), the plugin will use that string as the alias (e.g.,exports['./my-styles.css']). - If set to
false, the plugin will not generate an alias for the main CSS file (e.g.,exports['./style.css']will not be present), but individual CSS files (e.g.,exports['./dist/style.css']) will still be added if they exist.
css.extensions:string[](default:['.css'])- An array of file extensions to be treated as stylesheets.