Webpack 打包Javascript與將ES6編譯成ES5範例

相關參考可以點此 教學連結


webpack.config.js

const path = require('path');
module.exports = {
    entry: {
        index: './index.js'
    },
    output: {
        filename: 'bundle.js',
        path: path.resolve('./'),
    },
    module: {
        rules: [{
            use: {
                loader: 'babel-loader',
                options: {
                    presets: ['@babel/preset-env']
                }
            },
            test: /\.js$/
        }]
    }
};

package.json

{
  {
  "name": "hellow_webpack_test",
  "version": "1.0.0",
  "description": "webpack test project",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "york",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.4.3",
    "@babel/preset-env": "^7.4.3",
    "babel-core": "^6.26.3",
    "babel-loader": "^8.0.5",
    "babel-preset-env": "^1.7.0",
    "webpack": "^4.30.0"
  },
  "dependencies": {
    "webpack-cli": "^3.3.0"
  }
}