配置vue.config.js

configureWebpack值為對(duì)象的配置方式

const path = require('path')
const ThemeColorReplacer = require('webpack-theme-color-replacer')
const forElementUI = require('webpack-theme-color-replacer/forElementUI')
module.exports = {
    publicPath: '/', //基本路徑
    outputDir: 'dist', //構(gòu)建時(shí)的輸出目錄
    assetsDir: '', //放置靜態(tài)資源的目錄
    indexPath: 'index.html',  //html的輸出路徑
    filenameHashing: false, //文件名哈希
    lintOnSave: true, //eslint 是否在保存時(shí)檢查
    runtimeCompiler: true, //是否使用帶有瀏覽器內(nèi)編譯器的完整構(gòu)建版本
    productionSourceMap: process.env.NODE_ENV === 'production' ? false : true, //如果你不需要生產(chǎn)環(huán)境的 source map,可以將其設(shè)置為 false 以加速生產(chǎn)環(huán)境構(gòu)建
    configureWebpack: {
        resolve: {
            alias: {
                '@': path.resolve(__dirname, 'src'),
            },
        },
        plugins: [
            // 生成僅包含顏色的替換樣式(主題色等)
            new ThemeColorReplacer({
                fileName: 'style/theme-colors.[contenthash:8].css',
                matchColors: [
                    ...forElementUI.getElementUISeries(process.env.VUE_APP_ELEMENT_COLOR), // element-ui主色系列          
                ],
                externalCssFiles: ['./node_modules/element-ui/lib/theme-chalk/index.css'],
                changeSelector: forElementUI.changeSelector,
            })
        ]
    }, 
    // devServer: {
    //  proxy: {
    //      '/api': {
    //          target: 'http://192.168.0.136:8088', //需要代理的地址
    //          changeOrigin: true, //是否跨域
    //          // ws: true,  //是否啟用webSocket
    //          pathRewrite: {'/api': ''},
    //      },
    //  },
    // },
};

configureWebpack值為函數(shù)的配置方式

let CompressionWebpackPlugin = require("compression-webpack-plugin")

module.exports = {
   // publicPath: './',
   // 打包到子域下面  http://www.baidu.com/sub
   // publicPath: '/sub/', 
   // outputDir: "dist/sub",      //輸出目錄
   // productionSourceMap: process.env.NODE_ENV==='production' ? false : true,
   //配置webpack
   configureWebpack: config=>{
       let plugins = [
           new CompressionWebpackPlugin({
               algorithm: 'gzip', //壓縮方式
               test: /\.js$|\.css$/, //匹配壓縮文件
               threshold: 10240  //對(duì)大于10k壓縮
           })
       ]
       if (process.env.NODE_ENV === 'production') {
           config.mode = "production";
           config.plugins = [...config.plugins, ...plugins]
       }else{
           config.mode = "development"
       }
       Object.assign(config, {
           externals: {    //排除不需要依賴包
               vue: 'Vue',  //import Vue from 'vue'
               axios: 'axios' //import axios from 'axios'
           }
       })
   }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容