webpack4将ES6转化成ES5如何配置

Others 2021-03-03 08:07:20 2021-03-03 08:07:20 1592 次浏览

1、安装如下模块(webpack 4.x | babel-loader 8.x | babel 7.x)

       npm i -D babel-loader @babel/core @babel/preset-env
 
     或者安装如下模块(webpack 4.x | babel-loader 8.x | babel 7.x)

npm i -D babel-loader@7 babel-core babel-preset-env
2、在webpack.config.js中写如下配置

        rules: [
            { "test":/.m?js$/, use: {loader:"babel-loader", options:{presets:["@babel/preset-env"]}}, exclude:/node_modules|bower_components/}
        ]