webpack配置babel

src/test1.js

function f() {
    console.log(arguments)
}

function ff(a = 1) {
    console.log(a)
    return f(...arguments)
}
ff(1, 2, 3, 4)

 

 

webpack.config.js

module.exports = {
    entry: './src/test1.js',
    target: 'web',
    module: {
        rules: [
            {
                test: /\.m?js$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: [
                            [
                                '@babel/preset-env', {
                                    useBuiltIns: "usage",
                                    targets: {
                                        browsers: "last 2 versions, not ie <= 9"
                                    }
                                }
                            ]
                        ],
                        plugins: [
                            "@babel/transform-runtime",
                            "@babel/plugin-transform-modules-commonjs"
                        ]
                    }
                }
            }
        ]
    },
    mode: 'development'
    // mode: 'production',
};

 

 

package.json

{
  "name": "webpack-babel",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "webpack -p"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.12.10",
    "@babel/plugin-transform-modules-commonjs": "^7.12.1",
    "@babel/plugin-transform-runtime": "^7.12.10",
    "@babel/preset-env": "^7.12.11",
    "babel-loader": "^8.2.2",
    "webpack": "^4.44.1",
    "webpack-cli": "^3.3.12"
  },
  "dependencies": {
    "@babel/polyfill": "^7.12.1"
  }
}

 

posted @ 2021-01-24 12:11  413Xiaol  阅读(89)  评论(0编辑  收藏  举报