vue.config.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. 'use strict'
  2. const path = require('path')
  3. function resolve(dir) {
  4. return path.join(__dirname, dir)
  5. }
  6. const name = '微纳园' // page title
  7. const ip = '0.0.0.0' // dev port
  8. const port = 9525 // dev port
  9. const Webpack = require('webpack')
  10. // const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
  11. const CompressionPlugin = require('compression-webpack-plugin')
  12. module.exports = {
  13. // publicPath: '/mnpH5/', // 代理模式使用
  14. publicPath: '/lifelineH5/', // tomcat模式使用
  15. outputDir: 'dist',
  16. assetsDir: 'assets',
  17. lintOnSave: process.env.NODE_ENV === 'development',
  18. productionSourceMap: false,
  19. devServer: {
  20. open: true,
  21. host: ip,
  22. port: port,
  23. https: false,
  24. disableHostCheck: true,
  25. // 以上的ip和端口是我们本机的;下面为需要跨域的
  26. proxy: {
  27. // 配置跨域
  28. '/h5Server': {
  29. target: `http://2.22.195.139:8781/apiForProd`,
  30. // target: `http://lifeline.idea-sf.com/lifelineApi`,
  31. ws: true,
  32. changOrigin: true, // 允许跨域
  33. pathRewrite: {
  34. '^/h5Server': '' // 请求的时候使用这个server就可以
  35. }
  36. },
  37. '/server': {
  38. target: process.env.VUE_APP_API_URL,
  39. ws: true,
  40. changOrigin: true, // 允许跨域
  41. pathRewrite: {
  42. '^/server': '' // 请求的时候使用这个server就可以
  43. }
  44. }
  45. }
  46. },
  47. configureWebpack: {
  48. // provide the app's title in webpack's name field, so that
  49. // it can be accessed in index.html to inject the correct title.
  50. name: name,
  51. resolve: {
  52. alias: {
  53. '@': resolve('src')
  54. }
  55. },
  56. externals: {
  57. vue: 'Vue',
  58. 'vue-router': 'VueRouter',
  59. axios: 'axios',
  60. vant: 'vant',
  61. moment: 'moment'
  62. },
  63. plugins: [
  64. // new BundleAnalyzerPlugin({ // 插件在这里使用
  65. // analyzerHost: '127.0.0.1',
  66. // // 将在“服务器”模式下使用的端口启动HTTP服务器。
  67. // analyzerPort: 8889,
  68. // analyzerMode: 'server',
  69. // openAnalyzer: false
  70. // }),
  71. new Webpack.ProvidePlugin({
  72. $: 'jquery',
  73. jquery: 'jquery'
  74. }),
  75. new CompressionPlugin({
  76. // test: /\.(js|css)?$/i, // 哪些文件要压缩
  77. // filename: '[path].gz[query]', // 压缩后的文件名
  78. // algorithm: 'gzip', // 使用gzip压缩
  79. // minRatio: 1, // 压缩率小于1才会压缩
  80. // deleteOriginalAssets: true // 删除未压缩的文件,谨慎设置,如果希望提供非gzip的资源,可不设置或者设置为false
  81. filename: '[path].gz[query]', // 压缩后的文件名(保持原文件名,后缀加.gz)
  82. algorithm: 'gzip', // 使用gzip压缩
  83. test: new RegExp('\\.(' + ['js', 'css'].join('|') + ')$'), // 匹配文件名
  84. threshold: 10240, // 对超过10k的数据压缩
  85. minRatio: 0.8 // 压缩率小于0.8才会压缩
  86. })
  87. ]
  88. },
  89. css: {
  90. loaderOptions: {
  91. // 给 sass-loader 传递选项
  92. sass: {
  93. // @/ 是 src/ 的别名
  94. data: `@import "@/common/style/index.scss";`
  95. }
  96. }
  97. }
  98. }