vue.config.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 = 9528; // 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://lifeline.idea-sf.com/lifelineApi`,
  30. ws: true,
  31. changOrigin: true, // 允许跨域
  32. pathRewrite: {
  33. "^/h5Server": "" // 请求的时候使用这个server就可以
  34. }
  35. },
  36. "/server": {
  37. target: process.env.VUE_APP_API_URL,
  38. ws: true,
  39. changOrigin: true, // 允许跨域
  40. pathRewrite: {
  41. "^/server": "" // 请求的时候使用这个server就可以
  42. }
  43. }
  44. }
  45. },
  46. configureWebpack: {
  47. // provide the app's title in webpack's name field, so that
  48. // it can be accessed in index.html to inject the correct title.
  49. name: name,
  50. resolve: {
  51. alias: {
  52. "@": resolve("src")
  53. }
  54. },
  55. externals: {
  56. vue: "Vue",
  57. "vue-router": "VueRouter",
  58. axios: "axios",
  59. vant: "vant",
  60. moment: "moment"
  61. },
  62. plugins: [
  63. // new BundleAnalyzerPlugin({ // 插件在这里使用
  64. // analyzerHost: '127.0.0.1',
  65. // // 将在“服务器”模式下使用的端口启动HTTP服务器。
  66. // analyzerPort: 8889,
  67. // analyzerMode: 'server',
  68. // openAnalyzer: false
  69. // }),
  70. new Webpack.ProvidePlugin({
  71. $: "jquery",
  72. jquery: "jquery"
  73. }),
  74. new CompressionPlugin({
  75. // test: /\.(js|css)?$/i, // 哪些文件要压缩
  76. // filename: '[path].gz[query]', // 压缩后的文件名
  77. // algorithm: 'gzip', // 使用gzip压缩
  78. // minRatio: 1, // 压缩率小于1才会压缩
  79. // deleteOriginalAssets: true // 删除未压缩的文件,谨慎设置,如果希望提供非gzip的资源,可不设置或者设置为false
  80. filename: "[path].gz[query]", // 压缩后的文件名(保持原文件名,后缀加.gz)
  81. algorithm: "gzip", // 使用gzip压缩
  82. test: new RegExp("\\.(" + ["js", "css"].join("|") + ")$"), // 匹配文件名
  83. threshold: 10240, // 对超过10k的数据压缩
  84. minRatio: 0.8 // 压缩率小于0.8才会压缩
  85. })
  86. ]
  87. },
  88. css: {
  89. loaderOptions: {
  90. // 给 sass-loader 传递选项
  91. sass: {
  92. // @/ 是 src/ 的别名
  93. data: `@import "@/common/style/index.scss";`
  94. }
  95. }
  96. }
  97. };