1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| const path = require('path'); const webpack = require('webpack'); const HtmlWebpackPlugin = require('html-webpack-plugin'); // const CompressionWebpackPlugin = require('compression-webpack-plugin') // const productionGzipExtensions = ['js', 'css']
const docEnv = process.env.NODE_ENV; module.exports = { publicPath: docEnv === 'production' ? './' : './', outputDir: 'dist', assetsDir: 'assets', indexPath: 'index.html', lintOnSave: false, runtimeCompiler: true, productionSourceMap: false, css: { sourceMap: false, extract: true }, configureWebpack: { resolve: { alias: { '@': path.resolve(__dirname, './src'), '@base': path.resolve(__dirname, './'), } }, plugins: [ // 下面是下载的插件的配置 /* new CompressionWebpackPlugin({ algorithm: 'gzip', test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'), threshold: 10240, minRatio: 0.8 }), */ new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 5, minChunkSize: 1000 }), new HtmlWebpackPlugin({ // 打包输出HTML minify: { // 压缩HTML文件 removeComments: true, // 移除HTML中的注释 collapseWhitespace: true, // 删除空白符与换行符 minifyCSS: true// 压缩内联css }, filename: 'index.html', template: path.join(__dirname, 'index.html') }) ] }, /* chainWebpack: config => { config .plugin('html') .tap(args => { args[0].template = path.join(__dirname, 'index.html') return args }) }, */ devServer: { contentBase: path.join(__dirname, 'dist'), compress: false, port: 9000, clientLogLevel: 'silent', hot: true, index: 'index.html', inline: true, overlay: { warnings: true, errors: false }, proxy: { '/api': { // 此处的写法,目的是为了 将 /api 替换成 https://www.baidu.com/ // target: 'https://www.baidu.com/', target: '', // 允许跨域 changeOrigin: true, ws: true, pathRewrite: { '^/api': '' } }, '/service': { target: '', changeOrigin: true, ws: true, pathRewrite: { '^/service': '' } } } } }
|