vue.config.js 3.8 KB

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