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';
引入了打包以后的代码, 打印出来是这样的:
并没有模块导出, 但是之前在 webpack 里面打包成功了(代码一样, 打包配置不一样). 不知道我现在出了啥问题, 有没有大佬赐教.
看看这个:https://cn.vitejs.dev/guide/b...
另外学学 markdown 吧,哥们,没有缩进的代码阅读起来真的难受。