处理js
2018-09-22 本文已影响0人
visitor009
将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