vue.config.js 2.6 KB

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