ERROR in renderer.js from UglifyJs Unexpected token punc «(»

こ雲淡風輕ζ 提交于 2019-12-08 03:44:26

I struggle with a similar problem. That was the trick https://github.com/SimulatedGREG/electron-vue/issues/200

You can try to install this version of uglify, it called uglify-es and it is:

JavaScript parser, mangler/compressor and beautifier toolkit for ES6+

uglify-es npm link

In my case, I have installed babel plugin to handle this issue. If you want to try you should do this:

Add this to your package.json

"babel-core": "latest",
"babel-loader": "latest",
"babel-plugin-transform-async-to-generator": "latest",
"babel-plugin-transform-runtime": "latest",
"babel-preset-es2015": "latest",
"babel-runtime": "latest"

Set you webpack.config file to be like (This is mine for example):

const path = require('path')
const webpack = require('webpack')

module.exports = {
    entry: './src/main.js',
    output: {
        path: path.resolve(__dirname, './dist'),
        publicPath: '/dist/',
        filename: 'build.js'
    },
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: 'vue-loader'
            },
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/
            },
            {
                test: /\.(png|jpg|gif|svg)$/,
                loader: 'file-loader',
                query: {
                    name: '[name].[ext]?[hash]'
                }
            },
            {
                test: /\.scss$/,
                use: ['style-loader', 'css-loader', 'sass-loader']
            }
        ]
    }
}

if (process.env.NODE_ENV === 'production') {
    module.exports.devtool = '#source-map'
    module.exports.plugins = (module.exports.plugins || []).concat([
        new webpack.optimize.UglifyJsPlugin({ sourceMap: true, compress: { warnings: false }})
    ])
}

Set your .babelrc file to be like:

{
    "presets": ["es2015"],
    "plugins": ["transform-runtime", "transform-async-to-generator"]
}

Hope it helps :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!