vue.config多页配置


const CompressionWebpackPlugin = require('compression-webpack-plugin')
const path = require('path');
const glob = require('glob');
const fs = require('fs')

// 是否使用gzip
const productionGzip = true;
// 需要gzip压缩的文件后缀
const productionGzipExtensions = ['js', 'css'];
// CDN外链,会插入到index.html中

// 统一配置多页
function muliti() {
    const pages = {};
    glob.sync('./src/entries/**/main.js').forEach(path => {
        const chunk = path.split('./src/entries/')[1].split('/main.js')[0];//设置名称
        pages[chunk] = {
            entry: `src/entries/${chunk}/main.js`,
            template: `public/${chunk}.html`,
            filename: `${chunk}.html`,
            chunks: ['chunk-common', `${chunk}`]
        }

    });
    console.log('构建开始啦......................');
    return pages
}


module.exports = {
    // baseUrl: './', // 基本路径
    outputDir: 'dist', // 输出文件目录
    lintOnSave: false,
    pages: muliti(),
    // 配置merge
    configureWebpack: config => {
        //开启vs-code Debugger for Chrome
        config.devtool = 'source-map';
        config.optimization = {
            splitChunks: {
                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 `fanwenqiang.${packageName.replace('@', '')}`;
                        }
                    },
                }
            }
        };
        //Gzip压缩
    },
    runtimeCompiler: true,
    productionSourceMap: false, // 生产环境是否生成 sourceMap 文件
    devServer: {
        open: process.platform === 'darwin',
        host: '0.0.0.0',
        port: 9998,
        https: false,
        hotOnly: false,
        proxy: {
            '/a_api/*': {
                target: 'http://xxxx:4056/',
                changeOrigin: true,
                secure: false
            },
            '/arcgis/*': {
                target: 'http://xxxx:6080',
                changeOrigin: true,
                secure: false
            },
        }, // 设置代理
        before: app => { }
    },
    // 第三方插件配置
    pluginOptions: {}
};

你可能感兴趣的:(vue.config多页配置)