123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- const path = require('path');
- const CompressionWebpackPlugin = require("compression-webpack-plugin")
- const productionGzipExtensions = ['js', 'css']
- let debug =false;
- function resolve(dir) {
- return path.join(__dirname, dir)
- }
- let title = '';
- if (process.env.VUE_APP_NODE_NAME == 'production') {
- title = '';
- } else if (process.env.VUE_APP_NODE_NAME == 'test') {
- title = '(测试)';
- debug=true;
- } else {
- title = '(开发)';
- debug=true;
- }
- const Timestamp = new Date().getTime();
- module.exports = {
- pages: {
- index: {
- entry: 'src/main.js',
- template: 'public/index.html',
- filename: 'index.html',
- title: '12355' + title,
- }
- },
- publicPath: './',
- outputDir: 'dist/' + process.env.OUT_PUT_NAME,
- assetsDir: 'static',
- lintOnSave: false,
- devServer: {
- host: '0.0.0.0',
- port: 8080,
- //解析缓存
- disableHostCheck: true,
- //支持gzip
- compress: true,
- },
- //不输出map
- productionSourceMap: debug,
- chainWebpack: (config) => {
- config.entry.app = ['babel-polyfill', './src/main.js']
- config.resolve.alias
- .set('@', resolve('./src/'))
- config.plugins.delete('preload-index');
- config.plugins.delete('prefetch-index');
- config.optimization.minimize(true);
- },
- configureWebpack: config => {
- if (debug) { // 开发环境配置
- config.devtool = 'source-map'
- }
- /* //开启gzip压缩,需要配置Nginx服务器gzip选项开启
- config.plugins.push(
- new CompressionWebpackPlugin({
- filename: '[path].gz[query]',
- algorithm: 'gzip',
- test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
- threshold: 10240,
- minRatio: 0.8
- })
- ); */
- config.output.filename = `./static/js/[name].${Timestamp}.js`
- config.output.chunkFilename = `./static/js/[name].${Timestamp}.js`
- config.performance = {
- hints: 'warning',
- //入口起点的最大体积 整数类型(以字节为单位)
- maxEntrypointSize: 50000000,
- //生成文件的最大体积 整数类型(以字节为单位 300k)
- maxAssetSize: 30000000,
- //只给出 js 文件的性能提示
- assetFilter: function(assetFilename) {
- return assetFilename.endsWith('.js');
- }
- }
- },
- css: {
- extract: {
- filename: `./static/css/[name].${Timestamp}.css`,
- chunkFilename: `./static/css/[name].${Timestamp}.css`
- },
- sourceMap: false,
- loaderOptions: {
- // 给 sass-loader 传递选项
- sass: {
- // @/ 是 src/ 的别名
- // prependData: `@import "@/assets/scss/base.scss";`
- }
- }
- }
- };
|