vue 2.5 版本集成web3.js 过程中遇见了下面两个问题:
问题一:项目启动不了,会报识别不了...语法问题
vue 安装web3,babel默认不解析node_modules中内容,导致识别不了ES6语法报错。
问题解决:
在webpack.base.conf 配置文件中国,添加 resolve('node_modules/web3')
//修改webpack.base.conf配置
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client'), resolve('node_modules/web3')]
}
问题二:项目启动后,页面空白,控制台报错如下:
Cannot assign to read only property 'exports' of object
这是因为CommonJS和ES6的import和module.export 混用导致的,需要修改.babelrc 文件。
将.babelrc 文件plugins 的transform-runtime 删除 就不会报错了