No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

129 líneas
4.2 KiB

  1. 'use strict'
  2. const path = require('path')
  3. const defaultSettings = require('./src/settings.js')
  4. function resolve(dir) {
  5. return path.join(__dirname, dir)
  6. }
  7. const CompressionPlugin = require('compression-webpack-plugin')
  8. const name = process.env.VUE_APP_TITLE || '玻璃控股信息平台' // 网页标题
  9. const port = process.env.port || process.env.npm_config_port || 80 // 端口
  10. module.exports = {
  11. // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上
  12. // 例如 https://www.ruoyi.vip/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.ruoyi.vip/admin/,则设置 baseUrl 为 /admin/。
  13. publicPath: process.env.PUBLIC_PATH ? process.env.PUBLIC_PATH : '/',
  14. outputDir: 'dist',
  15. assetsDir: 'static',
  16. // 是否开启eslint保存检测,有效值:ture | false | 'error'
  17. lintOnSave: process.env.NODE_ENV === 'development',
  18. // 如果你不需要生产环境的 source map,可以将其设置为 false 以加速生产环境构建。
  19. productionSourceMap: false,
  20. // webpack-dev-server 相关配置
  21. devServer: {
  22. host: '0.0.0.0',
  23. port: port,
  24. open: true,
  25. proxy: {
  26. ['/proxy-api']: {
  27. target: `http://localhost:48080`,
  28. changeOrigin: true,
  29. pathRewrite: {
  30. ['^' + process.env.VUE_APP_BASE_API]: ''
  31. }
  32. }
  33. },
  34. disableHostCheck: true
  35. },
  36. css: {
  37. loaderOptions: {
  38. sass: {
  39. sassOptions: { outputStyle: "expanded" }
  40. }
  41. }
  42. },
  43. configureWebpack: {
  44. name: name,
  45. resolve: {
  46. alias: {
  47. '@': resolve('src')
  48. }
  49. },
  50. plugins: [
  51. // http://doc.ruoyi.vip/ruoyi-vue/other/faq.html#使用gzip解压缩静态文件
  52. new CompressionPlugin({
  53. cache: false, // 不启用文件缓存
  54. test: /\.(js|css|html)?$/i, // 压缩文件格式
  55. filename: '[path].gz[query]', // 压缩后的文件名
  56. algorithm: 'gzip', // 使用gzip压缩
  57. minRatio: 0.8 // 压缩率小于1才会压缩
  58. })
  59. ],
  60. },
  61. chainWebpack(config) {
  62. config.plugins.delete('preload') // TODO: need test
  63. config.plugins.delete('prefetch') // TODO: need test
  64. config.module
  65. .rule('svg')
  66. .exclude.add(resolve('src/assets/icons'))
  67. .end()
  68. config.module
  69. .rule('icons')
  70. .test(/\.svg$/)
  71. .include.add(resolve('src/assets/icons'))
  72. .end()
  73. .use('svg-sprite-loader')
  74. .loader('svg-sprite-loader')
  75. .options({
  76. symbolId: 'icon-[name]'
  77. })
  78. .end()
  79. config
  80. .when(process.env.NODE_ENV !== 'development',
  81. config => {
  82. config
  83. .plugin('ScriptExtHtmlWebpackPlugin')
  84. .after('html')
  85. .use('script-ext-html-webpack-plugin', [{
  86. // `runtime` must same as runtimeChunk name. default is `runtime`
  87. inline: /runtime\..*\.js$/
  88. }])
  89. .end()
  90. config
  91. .optimization.splitChunks({
  92. chunks: 'all',
  93. cacheGroups: {
  94. libs: {
  95. name: 'chunk-libs',
  96. test: /[\\/]node_modules[\\/]/,
  97. priority: 10,
  98. chunks: 'initial' // only package third parties that are initially dependent
  99. },
  100. elementUI: {
  101. name: 'chunk-elementUI', // split elementUI into a single package
  102. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  103. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  104. },
  105. commons: {
  106. name: 'chunk-commons',
  107. test: resolve('src/components'), // can customize your rules
  108. minChunks: 3, // minimum common number
  109. priority: 5,
  110. reuseExistingChunk: true
  111. }
  112. }
  113. })
  114. config.optimization.runtimeChunk('single'),
  115. {
  116. from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
  117. to: './', //到根目录下
  118. }
  119. }
  120. )
  121. }
  122. }