vue.config.js 3.3 KB

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