JS笔记:webpack基础es2015

2017-08-20  本文已影响8人  开水的杯子

Here are the basics of what we need to be able to write ES2015 code and get it compiled down to vanilla JS.

webpack.config.js

module.exports = {
    entry: "./src/index.js",
    output: {
        path: __dirname,
        filename: "./dist/index.js"
    },
    module: {
        rules: [
            {
              test: /\.js$/,
              exclude: /node_modules/,
              use: {
                loader: 'babel-loader',
                options: {
                  presets: ['env']
                }
              }
            }
          ]
    }
};

You need these dev dependencies in package.json:

"devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.0",
    "webpack": "^3.5.5"
  }

Now, running webpack will basically generate the vanilla JS code we need.

Testing

In order to make this work with tests:

{
     "presets": [ "env" ]
}
上一篇 下一篇

猜你喜欢

热点阅读