|
|
|
const webpack = require('webpack')
|
|
|
|
const path = require('path')
|
|
|
|
// const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
|
|
|
|
const CompressionWebpackPlugin = require('compression-webpack-plugin')
|
|
|
|
|
|
|
|
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
|
|
|
/**
|
|
|
|
* 配置参考:
|
|
|
|
* https://cli.vuejs.org/zh/config/
|
|
|
|
*/
|
|
|
|
|
|
|
|
// const url = 'http://47.94.55.72:9999/';//之前的线上地址
|
|
|
|
// const url = 'http://test.lovecode.cc:9999/';//线上地址
|
|
|
|
// const url = 'http://192.168.1.105:9999/';//线下地址
|
|
|
|
// const url = 'http:// 172.16.36.67:9999/';//线下地址
|
|
|
|
//
|
|
|
|
// const port = process.env.port || process.env.npm_config_port || 80 // 端口
|
|
|
|
const isProduction = process.env.NODE_ENV === 'production'
|
|
|
|
module.exports = {
|
|
|
|
// const port = process.env.port || process.env.npm_config_port || 80 // 端口
|
|
|
|
|
|
|
|
devServer: {
|
|
|
|
// https:true,
|
|
|
|
host: '0.0.0.0',
|
|
|
|
// port: port,
|
|
|
|
open: true,
|
|
|
|
proxy: {
|
|
|
|
// detail: https://cli.vuejs.org/config/#devserver-proxy
|
|
|
|
[process.env.VUE_APP_BASE_API]: {
|
|
|
|
// target: `https://www.keyitest.cn/prod-api`,
|
|
|
|
//target: `http://192.168.1.105:9999`,//之前
|
|
|
|
target: process.env.VUE_APP_BASE_TARGET,
|
|
|
|
changeOrigin: true,
|
|
|
|
pathRewrite: {
|
|
|
|
['^' + process.env.VUE_APP_BASE_API]: ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
disableHostCheck: true
|
|
|
|
// before (app, server) {
|
|
|
|
// app.get(/.*.(js)$/, (req, res, next) => {
|
|
|
|
// req.url = req.url + '.gz'
|
|
|
|
// res.set('Content-Encoding', 'gzip')
|
|
|
|
// next()
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
},
|
|
|
|
configureWebpack: {
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'@': path.resolve(__dirname, 'src')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
//
|
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
'window.Quill': 'quill/dist/quill.js',
|
|
|
|
Quill: 'quill/dist/quill.js'
|
|
|
|
}),
|
|
|
|
// new BundleAnalyzerPlugin()
|
|
|
|
new CompressionWebpackPlugin({
|
|
|
|
filename: '[path].gz[query]',
|
|
|
|
algorithm: 'gzip',
|
|
|
|
// test: /\.js$|\.html$|\.json$|\.css/,
|
|
|
|
test: /\.js$|\.json$|\.css/,
|
|
|
|
threshold: 10240, // 只有大小大于该值的资源会被处理
|
|
|
|
minRatio: 0.8 // 只有压缩率小于这个值的资源才会被处理
|
|
|
|
})
|
|
|
|
]
|
|
|
|
},
|
|
|
|
css: {
|
|
|
|
loaderOptions: {
|
|
|
|
scss: {
|
|
|
|
data: `@import "@/style/index.scss";`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
lintOnSave: true,
|
|
|
|
productionSourceMap: false,
|
|
|
|
chainWebpack: config => {
|
|
|
|
config.plugin('provide').use(webpack.ProvidePlugin, [
|
|
|
|
{
|
|
|
|
$: 'jquery',
|
|
|
|
jquery: 'jquery',
|
|
|
|
jQuery: 'jquery',
|
|
|
|
'window.jQuery': 'jquery'
|
|
|
|
}
|
|
|
|
])
|
|
|
|
// xss攻击
|
|
|
|
config.module
|
|
|
|
.rule('vue')
|
|
|
|
.use('vue-loader')
|
|
|
|
.loader('vue-loader')
|
|
|
|
.tap(options => {
|
|
|
|
options.compilerOptions.directives = {
|
|
|
|
html(node, directiveMeta) {
|
|
|
|
;(node.props || (node.props = [])).push({
|
|
|
|
name: 'innerHTML',
|
|
|
|
value: `Xss(_s(${directiveMeta.value}))`
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return options
|
|
|
|
})
|
|
|
|
// config.module
|
|
|
|
// .rule('images')
|
|
|
|
// .use('image-webpack-loader')
|
|
|
|
// .loader('image-webpack-loader')
|
|
|
|
// .options({
|
|
|
|
// bypassOnDebug: true
|
|
|
|
// })
|
|
|
|
// .end()
|
|
|
|
config.when(isProduction, config => {
|
|
|
|
config.plugin('UglifyJsPlugin').use('uglifyjs-webpack-plugin', [
|
|
|
|
{
|
|
|
|
uglifyOptions: {
|
|
|
|
output: {
|
|
|
|
comments: false // 去掉注释
|
|
|
|
},
|
|
|
|
warnings: false,
|
|
|
|
compress: {
|
|
|
|
drop_console: true,
|
|
|
|
drop_debugger: false,
|
|
|
|
pure_funcs: ['console.log'] //移除console
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
])
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// baseUrl: "/",//二级目录
|
|
|
|
// chainWebpack: config => {
|
|
|
|
// // 忽略的打包文件
|
|
|
|
// config.externals({
|
|
|
|
// 'axios': 'axios'
|
|
|
|
// });
|
|
|
|
// },
|
|
|
|
// 配置转发代理
|
|
|
|
// devServer: {
|
|
|
|
// disableHostCheck: true,
|
|
|
|
// proxy: {
|
|
|
|
// // '/static': {
|
|
|
|
// // target: url,
|
|
|
|
// // ws: true,
|
|
|
|
// // pathRewrite: {
|
|
|
|
// // '^/Resource': '/Resource'
|
|
|
|
// // }
|
|
|
|
// // },
|
|
|
|
// '/': {
|
|
|
|
// target: url,
|
|
|
|
// ws: true,
|
|
|
|
// pathRewrite: {
|
|
|
|
// '^/': '/'
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
}
|