@samara
To bundle a CommonJS module in Vite, you can use the rollup-plugin-commonjs plugin along with the Vite bundler. Here's a step-by-step guide on how to do it:
1
|
npm install rollup-plugin-commonjs --save-dev |
1 2 3 4 5 6 |
import { defineConfig } from 'vite'
import commonjs from 'rollup-plugin-commonjs'
export default defineConfig({
plugins: [commonjs()]
})
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import { defineConfig } from 'vite'
import commonjs from 'rollup-plugin-commonjs'
export default defineConfig({
plugins: [
commonjs({
include: 'node_modules/**',
namedExports: {
'some-commonjs-module': ['exportedFunction1', 'exportedFunction2']
}
})
]
})
|
Replace 'some-commonjs-module' with the name of the CommonJS module you want to bundle, and list the exported functions that you want to include in the bundle.
1
|
npx vite build |
After following these steps, your CommonJS module should be bundled with Vite using the rollup-plugin-commonjs plugin.