You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
4.5 KiB

3 years ago
3 years ago
3 years ago
  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. const CopyWebpackPlugin = require('copy-webpack-plugin')
  5. const webpack = require('webpack')
  6. function resolve(dir) {
  7. return path.join(__dirname, dir)
  8. }
  9. const name = defaultSettings.title || '若依管理系统' // 标题
  10. const port = process.env.port || process.env.npm_config_port || 80 // 端口
  11. // vue.config.js 配置说明
  12. //官方vue.config.js 参考文档 https://cli.vuejs.org/zh/config/#css-loaderoptions
  13. // 这里只列一部分,具体配置参考文档
  14. module.exports = {
  15. // 部署生产环境和开发环境下的URL。
  16. // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上
  17. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  18. publicPath: process.env.NODE_ENV === "production" ? "/" : "/",
  19. // 在npm run build 或 yarn build 时 ,生成文件的目录名称(要和baseUrl的生产环境路径一致)(默认dist)
  20. outputDir: 'dist',
  21. // 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下)
  22. assetsDir: 'static',
  23. // 是否开启eslint保存检测,有效值:ture | false | 'error'
  24. lintOnSave: process.env.NODE_ENV === 'development',
  25. // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  26. productionSourceMap: false,
  27. // webpack-dev-server 相关配置
  28. devServer: {
  29. host: '0.0.0.0',
  30. port: port,
  31. open: true,
  32. proxy: {
  33. // detail: https://cli.vuejs.org/config/#devserver-proxy
  34. [process.env.VUE_APP_BASE_API]: {
  35. // target: `http://127.0.0.1:8501/`,
  36. target: `http://47.104.146.186:8501/`,
  37. // target: `http://192.168.3.23:8501/`,
  38. changeOrigin: true,
  39. pathRewrite: {
  40. ['^' + process.env.VUE_APP_BASE_API]: ''
  41. }
  42. }
  43. },
  44. disableHostCheck: true
  45. },
  46. configureWebpack: {
  47. name: name,
  48. resolve: {
  49. alias: {
  50. '@': resolve('src')
  51. }
  52. }
  53. },
  54. chainWebpack(config) {
  55. config.plugins.delete('preload') // TODO: need test
  56. config.plugins.delete('prefetch') // TODO: need test
  57. // set svg-sprite-loader
  58. config.module
  59. .rule('svg')
  60. .exclude.add(resolve('src/assets/icons'))
  61. .end()
  62. config.module
  63. .rule('icons')
  64. .test(/\.svg$/)
  65. .include.add(resolve('src/assets/icons'))
  66. .end()
  67. .use('svg-sprite-loader')
  68. .loader('svg-sprite-loader')
  69. .options({
  70. symbolId: 'icon-[name]'
  71. })
  72. .end()
  73. // set preserveWhitespace
  74. config.module
  75. .rule('vue')
  76. .use('vue-loader')
  77. .loader('vue-loader')
  78. .tap(options => {
  79. options.compilerOptions.preserveWhitespace = true
  80. return options
  81. })
  82. .end()
  83. config
  84. .when(process.env.NODE_ENV !== 'development',
  85. config => {
  86. config
  87. .plugin('ScriptExtHtmlWebpackPlugin')
  88. .after('html')
  89. .use('script-ext-html-webpack-plugin', [{
  90. // `runtime` must same as runtimeChunk name. default is `runtime`
  91. inline: /runtime\..*\.js$/
  92. }])
  93. .end()
  94. config
  95. .optimization.splitChunks({
  96. chunks: 'all',
  97. cacheGroups: {
  98. libs: {
  99. name: 'chunk-libs',
  100. test: /[\\/]node_modules[\\/]/,
  101. priority: 10,
  102. chunks: 'initial' // only package third parties that are initially dependent
  103. },
  104. elementUI: {
  105. name: 'chunk-elementUI', // split elementUI into a single package
  106. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  107. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  108. },
  109. commons: {
  110. name: 'chunk-commons',
  111. test: resolve('src/components'), // can customize your rules
  112. minChunks: 3, // minimum common number
  113. priority: 5,
  114. reuseExistingChunk: true
  115. }
  116. }
  117. })
  118. config.optimization.runtimeChunk('single'),
  119. {
  120. from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
  121. to: './', //到根目录下
  122. }
  123. }
  124. )
  125. }
  126. }