vue.config.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. const path = require('path')
  2. // let targetUrl = 'http://admin.dayaedu.com'
  3. let targetUrl = 'http://192.168.3.28:8000/'
  4. // let targetUrl = 'http://192.168.3.27:8000' // 箭河
  5. // let targetUrl = 'http://192.168.3.48:8000'
  6. // let targetUrl = 'http://testadm.dayaedu.com/'
  7. // let targetUrl = 'https://mstuonline.dayaedu.com'
  8. // let version = '1.0.0'
  9. // webpack.prod.conf.js
  10. // const Version = new Date().getTime();
  11. // const Version = 20191227;
  12. const CompressionWebpackPlugin = require('compression-webpack-plugin')
  13. const productionGzipExtensions = ['js', 'css']
  14. function resolve (dir) {
  15. return path.join(__dirname, './', dir)
  16. }
  17. module.exports = {
  18. publicPath: './',
  19. // outputDir: 'dist',
  20. // assetsDir: 'static',
  21. // outputDir: 'dist',
  22. // 调整内部的 webpack 配置。
  23. // 查阅 https://github.com/vuejs/vue-doc-zh-cn/vue-cli/webpack.md
  24. // chainWebpack: () => {},
  25. // transpileDependencies: ['webpack-dev-server/client'],
  26. chainWebpack: config => {
  27. config.devtool('inline-source-map')
  28. config.output.filename('[name].[hash].js').end();
  29. // const svgRule = config.module.rule('svg')
  30. // // 清除已有的所有 loader,如果你不这样做,接下来的 loader 会附加在该规则现有的 loader 之后。
  31. // svgRule.uses.clear()
  32. // // 添加要替换的 loader
  33. // svgRule.use('svg-sprite-loader').loader('svg-sprite-loader')
  34. // .options({
  35. // symbolId: 'icon-[name]'
  36. // })
  37. // svg rule loader
  38. const svgRule = config.module.rule('svg') // 找到svg-loader
  39. svgRule.uses.clear() // 清除已有的loader, 如果不这样做会添加在此loader之后
  40. svgRule.exclude.add(/node_modules/) // 正则匹配排除node_modules目录
  41. svgRule // 添加svg新的loader处理
  42. .test(/\.svg$/)
  43. .use('svg-sprite-loader')
  44. .loader('svg-sprite-loader')
  45. .options({
  46. symbolId: 'icon-[name]'
  47. })
  48. // 修改images loader 添加svg处理
  49. const imagesRule = config.module.rule('images')
  50. imagesRule.exclude.add(resolve('src/icons'))
  51. config.module
  52. .rule('images')
  53. .test(/\.(png|jpe?g|gif|svg)(\?.*)?$/)
  54. config.plugin('html').tap(args => {
  55. args[0].minify = {
  56. removeAttributeQuotes: false
  57. }
  58. return args
  59. })
  60. },
  61. // eslint-loader 是否在保存的时候检查
  62. lintOnSave: true,
  63. // 是否使用包含运行时编译器的Vue核心的构建
  64. runtimeCompiler: false,
  65. // 生产环境 sourceMap
  66. productionSourceMap: false,
  67. // productionGzip: true,
  68. configureWebpack: (config) => {
  69. // process.env.NODE_ENV === 'production'
  70. // 生产环境
  71. config.plugins.push(
  72. new CompressionWebpackPlugin({
  73. filename: '[path].gz[query]', // 提示示compression-webpack-plugin@3.0.0的话asset改为filename
  74. algorithm: 'gzip',
  75. test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
  76. threshold: 10240,
  77. minRatio: 0.8
  78. })
  79. )
  80. },
  81. // 配置 webpack-dev-server 行为。
  82. devServer: {
  83. open: process.platform === 'darwin',
  84. host: '0.0.0.0',
  85. port: 9002,
  86. https: false,
  87. hotOnly: false,
  88. // 查阅 https://github.com/vuejs/vue-doc-zh-cn/vue-cli/cli-service.md#配置代理
  89. proxy: {
  90. '/contracts': {
  91. target: targetUrl,
  92. changeOrigin: true,
  93. ws: true,
  94. '^/contracts': '/contracts',
  95. xfwd: true
  96. },
  97. '/student-server': {
  98. target: targetUrl,
  99. changeOrigin: true,
  100. ws: true,
  101. '^/student-server': '/student-server',
  102. xfwd: true
  103. },
  104. '/api-cms': {
  105. target: targetUrl,
  106. changeOrigin: true,
  107. ws: true,
  108. '^/api-cms': '/api-cms',
  109. xfwd: true
  110. },
  111. '/api-student': {
  112. target: targetUrl,
  113. changeOrigin: true,
  114. ws: true,
  115. '^/api-student': '/api-student',
  116. xfwd: true
  117. },
  118. '/api-auth': {
  119. target: targetUrl,
  120. changeOrigin: true,
  121. ws: true,
  122. '^/api-auth': '/api-auth',
  123. xfwd: true
  124. },
  125. '/musicGroup': {
  126. target: targetUrl,
  127. changeOrigin: true,
  128. ws: true,
  129. '^/musicGroup': '/musicGroup',
  130. xfwd: true
  131. }
  132. }, // string | Object
  133. },
  134. css: {
  135. loaderOptions: {
  136. less: {
  137. modifyVars: {
  138. // red: '#03a9f4',
  139. blue: '#14928A',
  140. // orange: '#f08d49',
  141. // 'text-color': '#111'
  142. }
  143. }
  144. }
  145. },
  146. }