vite 提交PR 支持CJS引入 [已经被拒了]

原文链接: vite 提交PR 支持CJS引入 [已经被拒了]

看这个样子应该是已经支持了, 可能我fork的版本不对或者使用姿势不对吧

fork 后 clone 

新建分支并切换

git branch vite-feat-importCJS
git checkout vite-feat-importCJS

然后测试playground

yarn 换源, 尽量使用yarn, 否则会出现无法提交代码的诡异问题

yarn config set registry https://registry.npm.taobao.org

现在根目录下

yarn 
yarn build
yarn link

然后在playground

yarn
yarn link vite
yarn dev

存在多个link时使用unlink删除

yarn unlink vite

添加lodash测试组件, vite默认使用lodash-es库避免了引入问题

cjs转esm

这代码尤大看了想打人....

export async function cjsToEsm(source: string): Promise<string> {
  const plugin = require('babel-plugin-transform-commonjs')
  const { transformAsync } = require('@babel/core')
  const { code } = await transformAsync(source, {
    plugins: [plugin],
    sourceType: 'module'
  })
  return code
}

提交pr, 等待尤大过目...

评论

暂无评论