vue.config.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const webpack = require('webpack')
  2. const WebpackZipPlugin = require('webpack-zip-plugin')
  3. const CompressionPlugin = require('compression-webpack-plugin')
  4. const path = require('path')
  5. const IS_PROD = process.env.NODE_ENV === 'production'
  6. const productionGzipExtensions = ['html', 'js', 'css']
  7. function resolve(dir) {
  8. return path.join(__dirname, dir)
  9. }
  10. module.exports = {
  11. devServer: {
  12. host: '0.0.0.0',
  13. https: false, //false关闭https,true为开启
  14. open: true, //自动打开浏览器
  15. port: 8080,
  16. /* proxy: {
  17. '/static': {
  18. target: 'http://47.92.151.165:8080/',
  19. changeOrigin: true, //允许跨域
  20. pathRewrite: { //重写路径,这种是没有我们定义的前缀
  21. '^/static': '/'
  22. }
  23. }
  24. } */
  25. },
  26. outputDir: 'app/matrix/' + process.env.VUE_APP_M3_APP,
  27. productionSourceMap: false,
  28. configureWebpack: config => {
  29. // 生产环境
  30. if (IS_PROD) {
  31. return {
  32. plugins: [
  33. new CompressionPlugin({
  34. test: new RegExp(
  35. '\\.(' + productionGzipExtensions.join('|') + ')$'
  36. ),
  37. threshold:10240,
  38. minRatio: 1,
  39. deleteOriginalAssets:false
  40. }),
  41. new WebpackZipPlugin({
  42. initialFile: 'app',
  43. endPath: './',
  44. zipName: process.env.VUE_APP_M3_APP+'.zip',
  45. //frontShell: 'sed -i \'\' \'s/src="/src="\\/static\\/app\\/matrix\\/m3event/g\; s/href="/href="\\/static\\/app\\/matrix\\/m3event/g\' ./app/matrix/m3event/index.html',
  46. //frontShell: 'sed -i \'\' \'s/src="/src="\\/static\\/app\\/matrix\\/m3event/g\; s/href="/href="\\/static\\/app\\/matrix\\/m3event/g\' ./app/matrix/m3event/index.html',
  47. behindShell: './deploy.sh ' + process.env.VUE_APP_M3_HOST + ' ' + process.env.VUE_APP_M3_COMPANY + ' ' + process.env.VUE_APP_M3_USERNAME + ' "' + process.env.VUE_APP_M3_PASSWORD + '" ' + process.env.VUE_APP_M3_APP + ' ' + process.env.VUE_APP_M3_TITLE
  48. })
  49. ]
  50. }
  51. }
  52. },
  53. chainWebpack(config) {
  54. // ============压缩图片 start============
  55. config.module
  56. .rule('images')
  57. .use('image-webpack-loader')
  58. .loader('image-webpack-loader')
  59. .options({ bypassOnDebug: true })
  60. .end()
  61. // ============压缩图片 end============
  62. // set svg-sprite-loader
  63. config.module
  64. .rule('svg')
  65. .exclude.add(resolve('src/icons'))
  66. .end()
  67. config.module
  68. .rule('icons')
  69. .test(/\.svg$/)
  70. .include.add(resolve('src/icons'))
  71. .end()
  72. .use('svg-sprite-loader')
  73. .loader('svg-sprite-loader')
  74. .options({
  75. symbolId: 'icon-[name]'
  76. })
  77. .end()
  78. },
  79. publicPath: process.env.NODE_ENV === 'production'?'/static/app/matrix/'+process.env.VUE_APP_M3_APP:''
  80. }