vue.config.js 3.3 KB

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