Webpack4 使用 async/await,webpack 支持 async/await,webpack打包支持ES7的async/await语法

npm install --save-dev @babel/plugin-transform-async-to-generator

下面两种方式二选一

1.  .babelrc 

{
  "plugins": ["@babel/plugin-transform-async-to-generator"]
}

2.  webpack.config.js   (here部分)

module: {
        rules: [
            {
                test: /\.js$/,
                use: [
                    {
                        loader: "eslint-loader",
                        options: {
                            enforce: "pre"
                        }
                    }
                ],
                exclude: __dirname + "node_modules",
                include: __dirname + "src",
            },
            {
                test: /\.js$/,
                use: [
                    {
                        loader: "babel-loader",
                        options: {
                            presets: [
                                "@babel/preset-env"
                            ],
                            plugins: [
                                // here
                                "@babel/plugin-transform-async-to-generator",
                                "@babel/plugin-proposal-class-properties"
                            ]
                        }
                    }
                ]
            }
        ]
    }

 

你可能感兴趣的:(JavaScript,webpack)