vite 打包 react 组件库的问题?

新手上路,请多包涵

vite 打包 react 组件库的问题?
我最近在学习用 vite 打包一个组件库, 然后发布在 npm 上引入, 但是我打包以后发现并没有任何以组件名字命名的模块导出.

这是我的打包配置:

import path from 'path';

const buildConfig = {
build: {
rollupOptions: {
external: ['react'],
output: {
entryFileNames: 'index.js',
chunkFileNames: 'index.js',
assetFileNames: 'index.[ext]',
format: 'es'
},
input: {
index: path.join(__dirname, '../src/component/index.js')
}
}
}
};

export default buildConfig;

然后我的入口代码:

export { default as Button } from './button';

export { default as Input } from './input';

export { default as Sidebar } from './sidebar';

export { default as Navigation } from './navigation';

export { default as Menu } from './menu';

export { default as Table } from './table';

引入了打包以后的代码, 打印出来是这样的:
image.png
并没有模块导出, 但是之前在 webpack 里面打包成功了(代码一样, 打包配置不一样). 不知道我现在出了啥问题, 有没有大佬赐教.

阅读 4k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题