处理js

将es6的语法和方法编译成es5

$_> npm install -D babel-loader @babel/core @babel/preset-env @babel/polyfill
// webpack.config.js
let webpack = require('webpack');
let path = require('path');

module.exports = {
    entry: {
        main: './src/main.js'
    },
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: '[name].js'
    },
    module: {
        rules: [
          {
            test: /\.js$/,
            exclude: /(node_modules)/,
            use: {
              loader: 'babel-loader',
              options: {
                presets: ['@babel/preset-env']
              }
            }
          }
        ]
      }
}
// main.js
import '@babel/polyfill'; // 将es6的新方法转es5
// ...

压缩: UglifyjsWebpackPlugin

你可能感兴趣的:(处理js)