NetManage/vue.config.js

155 lines
4.1 KiB
JavaScript
Raw Permalink Normal View History

2023-08-24 16:28:23 +08:00
//const HtmlWebpackPlugin = require('html-webpack-plugin')
//const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin')
const path = require("path");
function resolve(dir) {
return path.join(__dirname, dir);
}
2023-09-11 16:57:40 +08:00
const CompressionWebpackPlugin = require('compression-webpack-plugin');
2023-08-24 16:28:23 +08:00
module.exports = {
2023-09-11 16:57:40 +08:00
configureWebpack: {
optimization: {
minimizer: [
new CompressionWebpackPlugin({
test: /\.(js|css|json|ico|svg|png|html|woff|ttf)$/, // 匹配文件名
algorithm: 'gzip', // 使用gzip压缩
//minRatio: 1, // 压缩率小于0.8才会压缩
threshold: 10, // 对超过5k的数据压缩
deleteOriginalAssets: true // 删除源文件
})
]
}
},
2023-08-24 16:28:23 +08:00
// lintOnSave: false,
// productionSourceMap: false,
// chainWebpack: config => {
// // 打包所有文件内嵌到html里面
// //把图片转成base64 limit:1e5 => 100000 kb ,小于这个大小都会转成base64,大于就会用链接引用图片
// config.module
// .rule('images')
// .use('url-loader')
// .loader('url-loader')
// .tap(options => Object.assign(options, {
// esModule: false,
// limit: 1e5
// }));
// //把字体图标相关文件转成base64
// config.module.rule('fonts').use('url-loader')
// .loader('url-loader')
// .tap(options => Object.assign(options, {
// limit: 1e5
// }));
// //把svg转成base64
// //const svgRule = config.module.rule('svg');
// //svgRule.uses.clear();
// config.module.rule('svg').
// use('url-loader')
// .loader('url-loader')
// .tap(options => ({
// esModule: false,
// limit: 1e5
// }));
// config.plugin('inline-source').use(require('html-webpack-inline-source-plugin'));
// config.plugin('html').tap(args => {
// args[0].inlineSource = '(.css|.js$)';
// return args;
// });
// }
//打入一个文件
// lintOnSave: false,
// productionSourceMap: false,
// publicPath: '', //使用相对路径
// indexPath: 'index.html',
// outputDir: 'dist',
// // assetsDir: 'static',
// productionSourceMap: false,
// chainWebpack: config => {
// config.plugin('preload').tap(args => {
// args[0].fileBlacklist.push(/\.css/, /\.js/);
// return args;
// })
// config.plugin('inline-source')
// .use(require('html-webpack-inline-source-plugin'))
// config.plugin("html").tap(args => {
// args[0].chunksSortMode = "none";
// args[0].inlineSource = '(\.css|\.js$)';
// return args;
// });
// config.resolve.alias //添加别名
// .set('@', resolve('src'))
// .set('@assets', resolve('src/assets'))
// .set('@components', resolve('src/components'));
// }
//打入一个文件另一个说法
// configureWebpack: {
// plugins: [
// new HtmlWebpackPlugin({
// title: 'JSON和PHP Array 互转',
// template: 'public/index.html',
// templateParameters: {
// BASE_URL: `/`
// },
// inlineSource: '.(js|css|scss|less)$' // embed all javascript and css inline
// }),
// new HtmlWebpackInlineSourcePlugin()
// ]
// },
/*分开打包*/
//打包不生成map文件
productionSourceMap: false,
//publicPath: process.env.NODE_ENV === "production" ? "/safeControl/" : "/",
2023-09-11 16:57:40 +08:00
// publicPath: process.env.NODE_ENV === "production" ? "http://127.0.0.1/dist" : "",
publicPath: process.env.NODE_ENV === "production" ? "" : "",
2023-08-24 16:28:23 +08:00
css: {
loaderOptions: {
less: {
javascriptEnabled: true
}
}
},
//关闭lint监测
lintOnSave: false,
//开发服务器配置
devServer: {
proxy: {
"/dist/img": {
target: 'http://localhost:8080/img',
//changeOrigin: true, // 是否改变域名
//ws: true,
pathRewrite: {
// 路径重写
"^/dist/img": "" // 这个意思就是以api开头的定向到哪里, 如果你的后边还有路径的话, 会自动拼接上
}
},
"/dist/video": {
target: 'http://localhost:8080/video',
//changeOrigin: true, // 是否改变域名
//ws: true,
pathRewrite: {
// 路径重写
"^/dist/video": "" // 这个意思就是以api开头的定向到哪里, 如果你的后边还有路径的话, 会自动拼接上
}
}
}
}
2023-09-11 16:57:40 +08:00
};