esm-optimize
v1.0.8
Published
optimize cjs to esm by vite
Downloads
45
Readme
ESM Optimize
拆分 vite2.0 optimize 能力,做到项目无关,同时不需要创建 vite.config 配置文件。根据入参找到具体的模块进行更新,方便上层业务根据实际情况决定要如何使用 optimize 能力。
使用方式
我们提供 cli 的形式或者模块的形式直接导入使用
$ npm i -g esm-optimize
$ esm react vue # 优化 react vue 模块
$ esm react vue --force # 删除 cache 目录 强制重新 optimize
$ esm react vue --shadowforce # 不删除 cache 目录 强制重新 optimize
$ esm react vue --config # 显示最终生成的 config
$ esm vue --withVersion # 生成后的文件带有 package.json version 版本号 include: ['vue'] => .vite/vue.2.6.12.js
生成后的文件与模块名一一对应,但如若存在多版本共存的情况则无法处理,需要上层业务手动处理。例如可能同时存在 vue2, vue3
vue
-> node_modules/.vite/vue.js
react
-> node_modules/.vite/react.js
以模块的形式导入使用
import { optimize } from 'esm-optimize'
await optimize({
root: string, // 默认为 cwd
optimizeCacheDir: string, // 默认的 vite 缓存文件夹为 `node_modules/.vite`
optimizeDeps: {
include: [] // 要处理的 模块
},
force: true, // 删除 cache文件夹 强制优化
shadowforce: true, // 不删除 cache文件夹 强制优化
withVersion: true // 生成后的文件带有版本号,通常使用于多版本共存的情况
})
完整配置
查看 vite 配置文档