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'
}
})
}
}