const path = require(‘path‘); const cwd = process.cwd(); const VueLoaderPlugin = require(‘vue-loader/lib/plugin‘); const { getHtmlWebpackPlugins, getEntry } = require(‘./utils‘); const TerserPlugin = require(‘terser-webpack-plugin‘); const entries = getEntry(); const config = { entry: entries, resolve: { extensions: [‘.js‘, ‘.vue‘], }, optimization: { splitChunks: { chunks: ‘async‘ // initial(初始块)、async(按需加载块)、all(全部块) }, minimize: true, minimizer: [ new TerserPlugin({ terserOptions: { safari10: true, }, }), ], }, externals: { vue: ‘Vue‘ }, module: { rules: [{ test: /\.vue$/, include: path.resolve(cwd, ‘src‘), use: [‘vue-loader‘] }, { test: /\.(css|postcss)$/, use: [‘vue-style-loader‘, ‘css-loader‘, { loader: ‘postcss-loader‘, }, ] }, { test: /\.(js)$/, include: path.resolve(cwd, ‘src‘), use: [{ loader: ‘babel-loader‘, options: { presets: [ [‘@babel/preset-env‘, { targets: { ios: 9, android: 5 } }] ], plugins: [ ["@babel/transform-runtime"] ] } }] } ] }, plugins: [ new VueLoaderPlugin(), ] }; module.exports = config;
npm install terser-webpack-plugin -dev --save