| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- const CompressionPlugin = require('compression-webpack-plugin');
- module.exports = {
- publicPath: './',
- outputDir: './www',
- assetsDir: 'static',
- productionSourceMap: false,
- lintOnSave: true,
- filenameHashing: true,
- devServer: {
- https: false,
- port: 4562
- },
- configureWebpack: () => {
- if (process.env.NODE_ENV === 'production') {
- return {
- plugins: [
- new CompressionPlugin({
- minRatio: 1, // 压缩率小于1才会压缩
- test: /\.js$|.html$|\.css$/, // 匹配文件名
- threshold: 10240, // 对超过10k的文件进行压缩
- deleteOriginalAssets: false // 是否删除原文件
- })
- ],
- optimization: {
- runtimeChunk: 'single',
- splitChunks: {
- chunks: 'all',
- maxInitialRequests: Infinity,
- minSize: 20000,
- cacheGroups: {
- vendor: {
- test: /[\\/]node_modules[\\/]/,
- name(module) {
- // get the name. E.g. node_modules/packageName/not/this/part.js
- // or node_modules/packageName
- const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
- // npm package names are URL-safe, but some servers don't like @ symbols
- return `npm.${packageName.replace('@', '')}`
- }
- }
- }
- }
- }
- }
- }
- }
- }
|