vue.config.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. 'use strict'
  2. const path = require('path')
  3. function resolve(dir) {
  4. return path.join(__dirname, dir)
  5. }
  6. const name = '鲸致CRM系统V1.0' // page title
  7. // If your port is set to 80,
  8. // use administrator privileges to execute the command line.
  9. // For example, Mac: sudo npm run
  10. // You can change the port by the following method:
  11. // port = 9527 npm run dev OR npm run dev --port = 9527
  12. const port = process.env.port || process.env.npm_config_port || 8080 // dev port
  13. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  14. module.exports = {
  15. /**
  16. * You will need to set publicPath if you plan to deploy your site under a sub path,
  17. * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
  18. * then publicPath should be set to "/bar/".
  19. * In most cases please use '/' !!!
  20. * Detail: https://cli.vuejs.org/config/#publicpath
  21. */
  22. publicPath: './',
  23. outputDir: 'dist',
  24. assetsDir: 'static',
  25. // lintOnSave: process.env.NODE_ENV === 'development',
  26. productionSourceMap: false,
  27. devServer: {
  28. port: port
  29. },
  30. configureWebpack: {
  31. // provide the app's title in webpack's name field, so that
  32. // it can be accessed in index.html to inject the correct title.
  33. name: name,
  34. resolve: {
  35. alias: {
  36. '@': resolve('src')
  37. }
  38. }
  39. },
  40. chainWebpack(config) {
  41. config.plugins.delete('preload') // TODO: need test
  42. config.plugins.delete('prefetch') // TODO: need test
  43. // set svg-sprite-loader
  44. config.module
  45. .rule('svg')
  46. .exclude.add(resolve('src/icons'))
  47. .end()
  48. config.module
  49. .rule('icons')
  50. .test(/\.svg$/)
  51. .include.add(resolve('src/icons'))
  52. .end()
  53. .use('svg-sprite-loader')
  54. .loader('svg-sprite-loader')
  55. .options({
  56. symbolId: 'icon-[name]'
  57. })
  58. .end()
  59. // set preserveWhitespace
  60. config.module
  61. .rule('vue')
  62. .use('vue-loader')
  63. .loader('vue-loader')
  64. .tap(options => {
  65. options.compilerOptions.preserveWhitespace = true
  66. return options
  67. })
  68. .end()
  69. config
  70. // https://webpack.js.org/configuration/devtool/#development
  71. .when(process.env.NODE_ENV === 'development',
  72. config => config.devtool('cheap-source-map')
  73. )
  74. config
  75. .when(process.env.NODE_ENV !== 'development',
  76. config => {
  77. config
  78. .plugin('ScriptExtHtmlWebpackPlugin')
  79. .after('html')
  80. .use('script-ext-html-webpack-plugin', [{
  81. // `runtime` must same as runtimeChunk name. default is `runtime`
  82. inline: /runtime\..*\.js$/
  83. }])
  84. .end()
  85. config
  86. .optimization.splitChunks({
  87. chunks: 'all',
  88. cacheGroups: {
  89. libs: {
  90. name: 'chunk-libs',
  91. test: /[\\/]node_modules[\\/]/,
  92. priority: 10,
  93. chunks: 'initial' // only package third parties that are initially dependent
  94. },
  95. elementUI: {
  96. name: 'chunk-elementUI', // split elementUI into a single package
  97. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  98. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  99. },
  100. commons: {
  101. name: 'chunk-commons',
  102. test: resolve('src/components'), // can customize your rules
  103. minChunks: 3, // minimum common number
  104. priority: 5,
  105. reuseExistingChunk: true
  106. }
  107. }
  108. })
  109. config.optimization.runtimeChunk('single')
  110. }
  111. )
  112. }
  113. }