关于iView的Notification编译出错的问题。

使用了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-adminwebpack配置, 有遇到过这种情况的吗?

求大神告知,感谢不尽,已经困扰好几天了。

阅读 3.2k
2 个回答

下载最新版本的 iview-admin 试了一下,没有遇到这个问题,升级一下试试

新手上路,请多包涵

很明显是压缩代码的时候找不到 hash key

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