vue.config.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. const { defineConfig } = require('@vue/cli-service')
  2. const path = require('path')
  3. function resolve(dir) {
  4. return path.join(__dirname, dir)
  5. }
  6. const NodePolyfillPlugin = require('node-polyfill-webpack-plugin')
  7. // const CompressionPlugin = require('compression-webpack-plugin')
  8. const name = process.env.VUE_APP_TITLE || 'SaaS协同平台' // 网页标题
  9. const port = process.env.port || process.env.npm_config_port || 80 // 端口
  10. // const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
  11. module.exports = defineConfig({
  12. transpileDependencies: [ // 转换非es6语法插件
  13. '@riophae/vue-treeselect'
  14. ],
  15. // 部署生产环境和开发环境下的URL。
  16. // 默认情况下,Vue CLI 会假设你的应用是被部署在一个域名的根路径上
  17. // 例如 https://www.benyuntech.com/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.benyuntech.com/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. // '/':{
  36. ws:false,
  37. // target: `http://192.168.2.32`,
  38. target: `https://oms.lzlxylsf.com`,
  39. // target:`http://192.168.1.75:8080`,
  40. // target: `http://47.107.53.207:9023`,
  41. changeOrigin: true,
  42. // pathRewrite: {
  43. // ['^' + process.env.VUE_APP_BASE_API]: ''
  44. // }
  45. }
  46. }
  47. },
  48. css: {
  49. loaderOptions: {
  50. sass: {
  51. sassOptions: { outputStyle: "expanded" }
  52. }
  53. }
  54. },
  55. pwa: {
  56. iconPaths: {
  57. favicon32 : 'favicon.ico',
  58. favicon16 : 'favicon.ico',
  59. appleTouchIcon: 'favicon.ico',
  60. maskIcon : 'favicon.ico',
  61. msTileImage : 'favicon.ico'
  62. }
  63. },
  64. configureWebpack: {
  65. name: name,
  66. resolve: {
  67. alias: {
  68. '@': resolve('src')
  69. }
  70. },
  71. // entry: {
  72. // 'editor.worker': 'monaco-editor/esm/vs/editor/editor.worker.js'
  73. // },
  74. plugins: [
  75. // new CompressionPlugin({
  76. // // cache: false, // 不启用文件缓存
  77. // test: /\.(js|css|html)?$/i, // 压缩文件格式
  78. // filename: '[path].gz[query]', // 压缩后的文件名
  79. // algorithm: 'gzip', // 使用gzip压缩
  80. // minRatio: 0.8 // 压缩率小于1才会压缩
  81. // }),
  82. new NodePolyfillPlugin(),
  83. // new MonacoWebpackPlugin({
  84. // languages: ["javascript","css","html","json","java"],
  85. // features: ["coreCommands", "find", "format", "folding", 'smartSelect', 'snippets', 'suggest', 'hover']
  86. // }),
  87. ],
  88. },
  89. chainWebpack(config) {
  90. config.plugins.delete('preload') // TODO: need test
  91. config.plugins.delete('prefetch') // TODO: need test
  92. // set svg-sprite-loader
  93. config.module
  94. .rule('svg')
  95. .exclude.add(resolve('src/assets/icons'))
  96. .end()
  97. config.module
  98. .rule('icons')
  99. .test(/\.svg$/)
  100. .include.add(resolve('src/assets/icons'))
  101. .end()
  102. .use('svg-sprite-loader')
  103. .loader('svg-sprite-loader')
  104. .options({
  105. symbolId: 'icon-[name]'
  106. })
  107. .end()
  108. config.module
  109. .rule('bpmnlintrc')
  110. .test(/\.bpmnlintrc$/)
  111. .use('bpmnlint-loader')
  112. .loader('bpmnlint-loader')
  113. .end()
  114. config
  115. .when(process.env.NODE_ENV !== 'development',
  116. config => {
  117. config
  118. .plugin('ScriptExtHtmlWebpackPlugin')
  119. .after('html')
  120. .use('script-ext-html-webpack-plugin', [{
  121. // `runtime` must same as runtimeChunk name. default is `runtime`
  122. inline: /runtime\..*\.js$/
  123. }])
  124. .end()
  125. config
  126. .optimization.splitChunks({
  127. chunks: 'all',
  128. cacheGroups: {
  129. libs: {
  130. name: 'chunk-libs',
  131. test: /[\\/]node_modules[\\/]/,
  132. priority: 10,
  133. chunks: 'initial' // only package third parties that are initially dependent
  134. },
  135. elementUI: {
  136. name: 'chunk-elementUI', // split elementUI into a single package
  137. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  138. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  139. },
  140. commons: {
  141. name: 'chunk-commons',
  142. test: resolve('src/components'), // can customize your rules
  143. minChunks: 3, // minimum common number
  144. priority: 5,
  145. reuseExistingChunk: true
  146. }
  147. }
  148. })
  149. config.optimization.runtimeChunk('single'),
  150. {
  151. from: path.resolve(__dirname, './public/robots.txt'), //防爬虫文件
  152. to: './' //到根目录下
  153. }
  154. }
  155. )
  156. }
  157. })