使用了iview-admin
模版搭建后台系统。
在dev
模式下一切正常。
当执行npm run build
的时候出现了下面的错误
ERROR in main.e53c38756696d4c01357.js from UglifyJs
Unexpected token: operator (>) [main.e53c38756696d4c01357.js:3795,84]
然后去具体位置查看,代码如下:
__WEBPACK_IMPORTED_MODULE_0__notification_vue___default.a.newInstance = properties => {
const _props = properties || {};
const Instance = new __WEBPACK_IMPORTED_MODULE_1_vue__["default"]({
data: _props,
render (h) {
return h(__WEBPACK_IMPORTED_MODULE_0__notification_vue___default.a, {
props: _props
});
}
});
const component = Instance.$mount();
document.body.appendChild(component.$el);
const notification = Instance.$children[0];
return {
notice (noticeProps) {
notification.add(noticeProps);
},
remove (name) {
notification.close(name);
},
component: notification,
destroy (element) {
notification.closeAll();
setTimeout(function() {
document.body.removeChild(document.getElementsByClassName(element)[0]);
}, 500);
}
};
};
第一行就是报错的地方,应该是=>
报错了,这是ES6语法,然后去查看了iview
源码对应的地方:
import Notification from './notification.vue';
import Vue from 'vue';
Notification.newInstance = properties => {
const _props = properties || {};
const Instance = new Vue({
data: _props,
render (h) {
return h(Notification, {
props: _props
});
}
});
const component = Instance.$mount();
document.body.appendChild(component.$el);
const notification = Instance.$children[0];
return {
notice (noticeProps) {
notification.add(noticeProps);
},
remove (name) {
notification.close(name);
},
component: notification,
destroy (element) {
notification.closeAll();
setTimeout(function() {
document.body.removeChild(document.getElementsByClassName(element)[0]);
}, 500);
}
};
};
export default Notification;
我查看了其他文件,包括这个报错的文件的其他部分,都是已经从ES6转换成了ES5的,就这一个地方没有转换,很奇怪,不知道是什么原因。
附上.babelrc
配置:
{
"presets": ["es2015", "stage-3"],
"plugins": ["transform-runtime", "transform-vue-jsx"],
"comments": true
}
webpack.base.config.js
配置:
{
test: /iview\/.*?js$/,
loader: 'babel-loader'
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.js[x]?$/,
include: [resolve('src')],
exclude: /node_modules/,
loader: 'happypack/loader?id=happybabel'
}
都是使用的iview-admin
的webpack
配置, 有遇到过这种情况的吗?
求大神告知,感谢不尽,已经困扰好几天了。
下载最新版本的 iview-admin 试了一下,没有遇到这个问题,升级一下试试