webpack打包组件库问题
打包的组件库就一个js,引用会报错
ReferenceError: exports is not defined
其中webpack主要代码是
webpackConfig.module .rule('js')
.test(/\.([jt])s$/)
.exclude.add(/node_modules/)
.end()
.use('babel-loader')
.loader('babel-loader')
.options({
presets: [
'@babel/preset-env',
'@babel/preset-typescript',
'@vue/babel-preset-jsx',
],
plugins: [
[
'@cyber/babel-plugin-component',
{ libraryName: 'element-ui', styleLibraryName: 'theme-chalk' },
],
'@babel/plugin-transform-regenerator',
'@babel/plugin-transform-runtime',
],
});
webpackConfig.output .path(resolve(cwd, 'dist'))
.filename('[name].js')
.libraryTarget('commonjs');
回答:
你的libraryTarget设置为commonjs,这将导出一个模块或包,把这句删掉就可以了
以上是 webpack打包组件库问题 的全部内容, 来源链接: utcz.com/p/935380.html