Preview
Install
npm i cjs2esmodule
// or
yarn add cjs2esmodule
Usage
Using in vite.js
This will use babel
to transform AST
. If it's too slow, prefer to use script version to transform files.
import { defineConfig } from 'vite'
import { cjs2esmVitePlugin } from 'cjs2esmodule'
export default defineConfig({
plugins: [cjs2esmVitePlugin()]
})
Using script to transform files.
Used glob
under the hood, so it will follow the pattern.
const { transformFiles } = require('cjs2esmodule')
transformFiles('./scripts/test.js')
transformFiles(['./utils/*.js', './components/*.js'])