transform require
into import
for ESM runtime compatibility
When old project migrate from webpack to vite, you may just want to run it instead of modifying every
require
syntax to newimport
syntax.
npm i unplugin-require-transform --save-dev
Vite
import { defineConfig } from 'vite'
import unPluginRequireTransform from 'unplugin-require-transform/vite'
export default defineConfig({
plugins: [
vue(),
unPluginRequireTransform.vite(),
// ...etc
],
})
- vue
require
transform - dedupe
import
- test for webpack and add demos