vue.config.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. const path = require('path')
  2. const webpack = require('webpack')
  3. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  4. const GenerateAssetPlugin = require('generate-asset-webpack-plugin')
  5. const Timestamp = new Date().getTime()
  6. const createServerConfig = function (compilation) {
  7. let config = { version: new Date().getTime() }
  8. return JSON.stringify(config)
  9. }
  10. const resolve = dir => {
  11. return path.join(__dirname, dir)
  12. }
  13. // 项目部署基础
  14. // 默认情况下,我们假设你的应用将被部署在域的根目录下,
  15. // 例如:https://www.my-app.com/
  16. // 默认:'/'
  17. // 如果您的应用程序部署在子路径中,则需要在这指定子路径
  18. // 例如:https://www.foobar.com/my-app/
  19. // 需要将它改为'/my-app/'
  20. // iview-admin线上演示打包路径: https://file.iviewui.com/admin-dist/
  21. const BASE_URL = process.env.NODE_ENV === 'production'
  22. ? '/'
  23. : '/';
  24. const ip = 'http://120.79.80.64:8050'
  25. //const ip = 'http://192.168.1.80:8300'
  26. module.exports = {
  27. devServer: {
  28. port: "8080", //代理端口
  29. open: false, //项目启动时是否自动打开浏览器,我这里设置为false,不打开,true表示打开
  30. headers: {
  31. 'Access-Control-Allow-Origin': '*',
  32. },
  33. proxy: {
  34. '/cloudApi': {
  35. target: ip,
  36. ws: true,
  37. pathRewrite: {
  38. '^/api': '/'
  39. }
  40. },
  41. '/purchaseContract': {
  42. target: ip,
  43. ws: true,
  44. pathRewrite: {
  45. '^/api': '/'
  46. }
  47. },
  48. '/supplier': {
  49. target: ip,
  50. ws: true,
  51. pathRewrite: {
  52. '^/api': '/'
  53. }
  54. },
  55. '/javaApi': {
  56. target: ip,
  57. ws: true,
  58. pathRewrite: {
  59. '^/api': '/'
  60. }
  61. },
  62. }
  63. },
  64. // Project deployment base
  65. // By default we assume your app will be deployed at the root of a domain,
  66. // e.g. https://www.my-app.com/
  67. // If your app is deployed at a sub-path, you will need to specify that
  68. // sub-path here. For example, if your app is deployed at
  69. // https://www.foobar.com/my-app/
  70. // then change this to '/my-app/'
  71. publicPath: BASE_URL,
  72. // tweak internal webpack configuration.
  73. // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
  74. // 如果你不需要使用eslint,把lintOnSave设为false即可
  75. lintOnSave: true,
  76. chainWebpack: config => {
  77. config.resolve.alias
  78. .set('@', resolve('src')) // key,value自行定义,比如.set('@@', resolve('src/components'))
  79. .set('_c', resolve('src/components'))
  80. },
  81. // 设为false打包时不生成.map文件
  82. productionSourceMap: false,
  83. configureWebpack: config => {
  84. // 开发环境不需要gzip 生产环境时清空所有console
  85. if (process.env.NODE_ENV !== 'production') return
  86. else config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
  87. config.plugins.push(
  88. new CompressionWebpackPlugin({
  89. // 正在匹配需要压缩的文件后缀
  90. test: /\.(js|css|svg|woff|ttf|json|html)$/,
  91. // 大于10kb的会压缩
  92. threshold: 10240
  93. // 其余配置查看compression-webpack-plugin
  94. })
  95. )
  96. config.plugins.push(
  97. new GenerateAssetPlugin({
  98. filename: 'version.json',
  99. fn: (compilation, cb) => {
  100. cb(null, createServerConfig(compilation))
  101. },
  102. extraFiles: []
  103. })
  104. )
  105. config.plugins.push(
  106. new webpack.ProvidePlugin({
  107. $: 'jquery',
  108. jQuery: 'jquery',
  109. 'window.jQuery': 'jquery'
  110. })
  111. )
  112. config.output.filename = `js/[name].${Timestamp}.js`
  113. config.output.chunkFilename = `js/[name].${Timestamp}.js`
  114. }
  115. // 这里写你调用接口的基础路径,来解决跨域,如果设置了代理,那你本地开发环境的axios的baseUrl要写为 '' ,即空字符串
  116. // devServer: {
  117. // proxy: 'localhost:3000'
  118. // }
  119. }