代码拉取完成,页面将自动刷新
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['js', 'css']
const isProduction = process.env.NODE_ENV === 'production'
const webpack = require('webpack');
const path = require('path');
module.exports = {
publicPath: './',
// assetsPublicPath: "/",
//禁用eslint检查
lintOnSave: false,
outputDir: "develop",
publicPath: '/develop/',
productionSourceMap: false,
//代理服务器设置解决跨域的问题
devServer: {
//防止代理服务器,访问时显示:Invalid Host header
disableHostCheck: true,
open: true,
port: 80,
proxy: {
//新增一个服务器需要配置一个转发地址
'/api/server2': {
target: 'https://server2.cdkjcloud.com',
changeOrigin: true,
ws: true,
pathRewrite: {
'^/api/server2': ''
}
},
'/ping': {
target: 'https://server2.cdkjcloud.com',
changeOrigin: true,
ws: true,
pathRewrite: {
'^/ping': ''
}
},
'/wx': {
target: 'https://api.weixin.qq.com',
changeOrigin: true,
ws: true,
pathRewrite: {
'^/wx': ''
}
},
}
},
configureWebpack: config => {
// 公共代码抽离
config.optimization = {
splitChunks: {
cacheGroups: {
vendor: {
chunks: 'all',
test: /node_modules/,
name: 'vendor',
minChunks: 1,
maxInitialRequests: 5,
minSize: 0,
priority: 100
}
}
}
}
},
configureWebpack:{
// devtool: '#eval-source-map',
resolve:{
alias:{
'@':path.resolve(__dirname, './src'),
'@i':path.resolve(__dirname, './src/assets'),
}
},
plugins: [
// Ignore all locale files of moment.js
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// 配置compression-webpack-plugin压缩
new CompressionWebpackPlugin({
algorithm: 'gzip',
test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
threshold: 10240,
minRatio: 0.8
}),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 5,
minChunkSize: 100
})
]
},
chainWebpack: config => {
// 精简js文件
config.optimization.minimize(true);
// 移除多余插件,避免加载多余资源
config.plugins.delete('prefetch');
},
css: {
loaderOptions: {
css: {
// options here will be passed to css-loader
},
postcss: {
// options here will be passed to postcss-loader
plugins:[require('postcss-px2rem')({
remUnit: 37.5 //要除以2因为是2倍图,除以2因为第三方插件是1倍的,这里是设计稿的尺寸是750px
})]
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。