vue.config.js 3.5 KB

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