鍍金池/ 問答/HTML/ 關(guān)于iView的Notification編譯出錯的問題。

關(guān)于iView的Notification編譯出錯的問題。

使用了iview-admin模版搭建后臺系統(tǒng)。

dev模式下一切正常。

當(dāng)執(zhí)行npm run build的時候出現(xiàn)了下面的錯誤

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);
        }
    };
};

第一行就是報錯的地方,應(yīng)該是=>報錯了,這是ES6語法,然后去查看了iview源碼對應(yīng)的地方:

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;

我查看了其他文件,包括這個報錯的文件的其他部分,都是已經(jīng)從ES6轉(zhuǎn)換成了ES5的,就這一個地方?jīng)]有轉(zhuǎn)換,很奇怪,不知道是什么原因。

附上.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配置, 有遇到過這種情況的嗎?

求大神告知,感謝不盡,已經(jīng)困擾好幾天了。

回答
編輯回答
使勁操

下載最新版本的 iview-admin 試了一下,沒有遇到這個問題,升級一下試試

2018年4月28日 11:50
編輯回答
雨蝶

很明顯是壓縮代碼的時候找不到 hash key

2017年1月13日 01:16