Native Waiting / Asynchronous and Web Package

I am developing an extension for chrome 55+ and use webpack 2 to do everything. The problem is that I started using async and am waiting.

The error I get is:

ERROR in content_script.js from UglifyJs
Unexpected token: keyword (function) [./content_script.js:1,0]
[content_script.js:1630,6]

For a simple file like this:

async function test() {

}

I do not want to use babel to convert it to a frivolous asynchronous code due to the fact that only 55+ hard anyway, but I can not find a way to configure UglifyJs to accept this, or use another version that supports it.

My webpack configuration:

var path = require("path");
var webpack = require("webpack");
var CopyWebpackPlugin = require("copy-webpack-plugin");
var HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
    entry: {
        "content_script": [
            "./content_script.js"
        ],
        "browser_action": [
            "./browser_action.js"
        ],
        "background": [
            "./background.js"
        ],
        "options": [
            "./options.js"
        ]
    },
    node: {
        fs: "empty"
    },
    output: {
        path: __dirname + "/dist",
        filename: "[name].js"
    },
    plugins: [
        new CopyWebpackPlugin([
            { from: "manifest.json" }
        ]),
        new HtmlWebpackPlugin({
            template: path.join(__dirname, "browser_action_popup.html"),
            inject: true,
            chunks: ["browser_action"],
            hash: false,
            filename: "browser_action_popup.html"
        }),
        new HtmlWebpackPlugin({
            template: path.join(__dirname, "options.html"),
            inject: true,
            chunks: ["options"],
            hash: false,
            filename: "options.html"
        })
    ]
};
+4
source share
1 answer

UglifyJs does not yet understand the syntax of ES2015 +. Alternatively, you can use babili , which works with every syntax that babel understands.

babili-webpack-plugin, webpack.optimize.UglifyJsPlugin webpack.

const BabiliPlugin = require('babili-webpack-plugin');

module.exports = {
  // ...

  plugins: [
      new BabiliPlugin(options)
  ]
};

. babel-preset-babili.

babili CLI, webpack.

+3

Source: https://habr.com/ru/post/1673418/


All Articles