vue.config.js 5.42 KB
Newer Older
fukai committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const publicPath = require('./src/config/isc-publicPath.js')
const baseData = require('./src/config/isc-baseData.js')
let moment = require("moment")

process.env.VUE_APP_BASETHEME = 'purple';
if (process.env.NODE_ENV === 'production') {
	process.env.VUE_APP_VERSION = moment(new Date()).format('YYYYMMDD HHmmss')
}
const WebpackBundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['js', 'css']

function resolve(dir) {
	return path.join(__dirname, dir)
}

module.exports = {
	publicPath: publicPath + '/',
	outputDir: 'sstf',
	assetsDir: 'static',
	productionSourceMap: false,
	runtimeCompiler: true,
	devServer: {
		inline: true,
		disableHostCheck: true,
		port: 8088,
		//proxy: baseData.schemes + '://' +baseData.host,
		proxy: {
zenghuan committed
31 32 33 34 35 36 37
			'/webapi/gjzf/': {
				target: baseData.schemes + '://' + baseData.hostGjzf,
				changeOrigin: false,
				pathRewrite: {
					'^/webapi/gjzf': '/gjzf'
				}
			},	
fukai committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
			'/webapi/manager/': {
				target: baseData.schemes + '://' + baseData.host,
				changeOrigin: false,
				pathRewrite: {
					'^/webapi/manager': '/manager'
				}
			},
			'/webapi/admin/': {
				target: baseData.schemes + '://' + baseData.hostAdmin,
				changeOrigin: false,
				pathRewrite: {
					'^/webapi/admin': '/admin'
				}
			},
			'/webapi/public/': {
				target: baseData.schemes + '://' + baseData.hostPublic,
				changeOrigin: true,
				pathRewrite: {
					'^/webapi/public': '/webapi'
				}
			},
			'/webapi/business/': {
				target: baseData.schemes + '://' + baseData.hostBusiness,
				changeOrigin: true,
				pathRewrite: {
					'^/webapi/business': '/webapi'
				}
      },
      '/webapi/Financing/': {
				target: baseData.schemes + '://' + baseData.hostFinance,
				changeOrigin: true,
				pathRewrite: {
					'^/webapi/Financing': '/webapi'
				}
      },
      '/webapi/Remittance/': {
				target: baseData.schemes + '://' + baseData.hostRemittance,
				changeOrigin: true,
				pathRewrite: {
					'^/webapi/Remittance': '/webapi/Remittance'
				}
      },
      '/webapi/Lc/': {
				target: baseData.schemes + '://' + baseData.hostLc,
				changeOrigin: true,
				pathRewrite: {
					'^/webapi/Lc': '/webapi'
				}
      },
      '/webapi/Domlc/': {
				target: baseData.schemes + '://' + baseData.hostDomlc,
				changeOrigin: true,
				pathRewrite: {
					'^/webapi/Domlc': '/webapi'
				}
      },
      '/webapi/Collection/': {
				target: baseData.schemes + '://' + baseData.hostCollection,
				changeOrigin: true,
				pathRewrite: {
					'^/webapi/Collection': '/webapi'
				}
      },
      '/webapi/Derivative/': {
				target: baseData.schemes + '://' + baseData.hostDerivative,
				changeOrigin: true,
				pathRewrite: {
					'^/webapi/Derivative': '/webapi'
				}
			},
			'/webapi/report/': {
				target: baseData.schemes + '://' + baseData.hostReport,
				changeOrigin: true,
				pathRewrite: {
					'^/webapi/report': '/webapi'
				}
			},
			'': {
				target: baseData.schemes + '://' + baseData.host,
				changeOrigin: true
			}
		},
		historyApiFallback: {
			verbose: true,
			rewrites: [{
					from: /^((?!\/webscan).)+$/,
					to: "/index.html"
				},
				{
					from: /^\/webscan.*$/,
					to: "/scanuse.html"
				},
			]
		}
	},
	chainWebpack: config => {
		config.resolve.alias
      .set('~', resolve('src'))
    config.externals ({'BopRules': 'BopRules','RcpmisRules':'RcpmisRules','CFARules':'CFARules','JSHRules':'JSHRules'})
	},
	configureWebpack: config => {
		if (process.env.NODE_ENV !== 'production') {
			// 开发环境下的source map配置
			config.devtool = 'source-map';
		}
		if (process.env.NODE_ENV === 'production') {
			// 将每个依赖包打包成单独的js文件
			let optimization = {
				runtimeChunk: 'single',
				splitChunks: {
					// chunks: 'all', 
					maxInitialRequests: Infinity,
					minSize: 20000, // 依赖包超过20000bit将被单独打包
					cacheGroups: {
						//官方名称
						vendors: {
							test: /[\\/]node_modules[\\/]/,
							//enforce: true,
							name(module) {
								// or node_modules/packageName
								const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
								// npm package names are URL-safe, but some servers don't like @ symbols
								return `npm.${packageName.replace('@', '')}`
							}
						},
					}
				}
			}
			Object.assign(config, {
				optimization
			})
			//放开下行注释可以分析打包体积分布
			//config.plugins.push(new WebpackBundleAnalyzerPlugin())
			//开启gizp压缩
			config.plugins.push(new CompressionWebpackPlugin({
				algorithm: 'gzip',
				test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
				threshold: 10240,
				minRatio: 0.8
			}))
		}

		config.plugins.push(new CopyWebpackPlugin([{
			from: path.resolve(__dirname + '/static'),
			to: path.resolve(__dirname + '/sstf/static'),
			toType: 'dir'
		},  
		{
			from: path.resolve(__dirname + '/testf5.html'),
			to: path.resolve(__dirname + '/sstf/testf5.html')
    }]))
	},
	pages: {
		index: {
			entry: "src/main.js",
			template: "index.html",
      filename: "index.html",
      chunks: 'all'
		}
	// 	,
	// 	scanuse: {
	// 		entry: "src/scanuse.js",
	// 		template: "scanuse.html",
    //   filename: "scanuse.html",
    //   chunks: ["chunk-vendors","chunk-common","scanuse","runtime"]
	// 	}
	},
	transpileDependencies: ['sock-js', 'sockjs-client']
}