Extensive_Web/vue.config.js

124 lines
3.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

const path = require('path')
// 导入compression-webpack-plugin 开启gzip
const CompressionWebpackPlugin = require('compression-webpack-plugin')
// 定义压缩文件类型
const productionGzipExtensions = ['js', 'css']
function resolve (dir) {
return path.join(__dirname, dir)
}
module.exports = {
publicPath: '/',
lintOnSave: true,
// 打包时不生成.map文件
productionSourceMap: false,
chainWebpack: (config) => {
// 配置静态资源图片
config.module.rules.delete('images')
// 清除svg默认的处理方式
config.module.rules.delete('svg')
config.plugin('html').tap(args => {
args[0].title = 'Elevate Imaging'
return args
})
},
configureWebpack: {
devtool: 'source-map',
resolve: {
extensions: ['.js', '.vue', '.json'], // 当引入文件时默认先找.js后缀的文件没找到再从左往右继续
alias: {
vue$: 'vue/dist/vue.esm.js',
'@': resolve('src')
}
},
plugins: [
new CompressionWebpackPlugin({
filename: '[path].gz[query]',
algorithm: 'gzip',
test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'), // 匹配文件名
threshold: 10240, // 对10K以上的数据进行压缩
minRatio: 0.8,
deleteOriginalAssets: false // 是否删除源文件
})
// new WebpackAliyunOss({
// from: ['./dist/**'], // 上传那个文件或文件夹 可以是字符串或数组
// dist: "/tydist", // 需要上传到oss上的给定文件目录
// region: "oss-cn-hangzhou",
// accessKeyId: "LTAI5tGR1NwGgA9fBQGxbUVa",
// accessKeySecret: "Xp4kbhFoEywD9aHQVopnThiyZbBQBp",
// bucket: "hbbwgczx",
// overwrite: true, // 是否需要覆盖bucket上的同名文件
// // test: true,
// //上面一行,可以在进行测试看上传路径是否正确, 打开后只会显示上传路径并不会真正上传;
// // 因为文件标识符 "" 和 "/" 的区别 不进行 setOssPath配置,上传的文件夹就会拼到文件名上, 丢失了文件目录,所以需要对setOssPath 配置。
// setOssPath: filePath => {
// let index = filePath.lastIndexOf("dist");
// let Path = filePath.substring(index + 4, filePath.length);
// return Path.replace(/\\/g, "/");
// },
// setHeaders: filePath => {
// return {
// "Cache-Control": "max-age=31536000"
// };
// }
// })
],
performance: {
hints: false
},
module: {
rules: [
{
test: /\.svg$/,
loader: 'svg-sprite-loader',
include: [resolve('src/static/icons')],
options: {
symbolId: 'icon-[name]'
}
},
{
test: /\.(png|jpe?g|gif|webp|svg)(\?.*)?$/,
exclude: [resolve('src/static/icons')],
use: [
{
loader: 'url-loader',
options: {
limit: 4096,
fallback: {
loader: 'file-loader',
options: {
name: 'img/[name].[hash:8].[ext]'
}
}
}
}
]
}
]
}
},
devServer: {
// https: true,
host: '0.0.0.0',
port: 9528,
proxy: {
[process.env.VUE_APP_BASE_API]: {
target: 'http://123.56.94.154:9530',
changeOrigin: true,
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: '/api/v1'
}
},
'/img_url': {
target: 'http://123.56.94.154:9530',
changeOrigin: true,
pathRewrite: {
'^/img_url': ''
}
}
}
}
}