vue.config.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. const Setting = require('./src/setting.env');
  2. // 拼接路径
  3. const resolve = dir => require('path').join(__dirname, dir);
  4. // 增加环境变量
  5. process.env.VUE_APP_VERSION = require('./package.json').version;
  6. process.env.VUE_APP_BUILD_TIME = require('dayjs')().format('YYYY-M-D HH:mm:ss');
  7. module.exports = {
  8. publicPath: Setting.publicPath,
  9. lintOnSave: Setting.lintOnSave,
  10. outputDir: Setting.outputDir,
  11. assetsDir: Setting.assetsDir,
  12. runtimeCompiler: true,
  13. productionSourceMap: false,
  14. devServer: {
  15. publicPath: Setting.publicPath
  16. },
  17. css: {
  18. loaderOptions: {
  19. less: {
  20. }
  21. }
  22. },
  23. transpileDependencies: ['view-design'],
  24. // 默认设置: https://github.com/vuejs/vue-cli/tree/dev/packages/@vue/cli-service/lib/config/base.js
  25. chainWebpack: config => {
  26. /**
  27. * 删除懒加载模块的 prefetch preload,降低带宽压力
  28. * https://cli.vuejs.org/zh/guide/html-and-static-assets.html#prefetch
  29. * https://cli.vuejs.org/zh/guide/html-and-static-assets.html#preload
  30. * 而且预渲染时生成的 prefetch 标签是 modern 版本的,低版本浏览器是不需要的
  31. */
  32. config.plugins
  33. .delete('prefetch')
  34. .delete('preload');
  35. // 解决 cli3 热更新失效 https://github.com/vuejs/vue-cli/issues/1559
  36. config.resolve
  37. .symlinks(true);
  38. config
  39. // 开发环境
  40. .when(process.env.NODE_ENV === 'development',
  41. // sourcemap不包含列信息
  42. config => config.devtool('cheap-source-map')
  43. )
  44. // 非开发环境
  45. .when(process.env.NODE_ENV !== 'development', config => {
  46. });
  47. // 不编译 iView Pro
  48. config.module
  49. .rule('js')
  50. .test(/\.jsx?$/)
  51. .exclude
  52. .add(resolve('src/libs/iview-pro'))
  53. .end();
  54. // 使用 iView Loader
  55. config.module
  56. .rule('vue')
  57. .test(/\.vue$/)
  58. .use('iview-loader')
  59. .loader('iview-loader')
  60. .tap(() => {
  61. return Setting.iviewLoaderOptions
  62. })
  63. .end();
  64. // markdown
  65. config.module
  66. .rule('md')
  67. .test(/\.md$/)
  68. .use('text-loader')
  69. .loader('text-loader')
  70. .end();
  71. // i18n
  72. config.module
  73. .rule('i18n')
  74. .resourceQuery(/blockType=i18n/)
  75. .use('i18n')
  76. .loader('@kazupon/vue-i18n-loader')
  77. .end();
  78. // image exclude
  79. const imagesRule = config.module.rule('images');
  80. imagesRule
  81. .test(/\.(png|jpe?g|gif|webp|svg)(\?.*)?$/)
  82. .exclude
  83. .add(resolve('src/assets/svg'))
  84. .end();
  85. // 重新设置 alias
  86. config.resolve.alias
  87. .set('@api', resolve('src/api'));
  88. // node
  89. config.node
  90. .set('__dirname', true)
  91. .set('__filename', true);
  92. // 判断是否需要加入模拟数据
  93. const entry = config.entry('app');
  94. if (Setting.isMock) {
  95. entry
  96. .add('@/mock')
  97. .end()
  98. }
  99. }
  100. };