vue.config.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. const fs = require('fs')
  2. const { env } = require('process')
  3. const path = require('path')
  4. const { CleanWebpackPlugin } = require('clean-webpack-plugin')
  5. const { defineConfig } = require('@vue/cli-service')
  6. const Timestamp = new Date().getTime();
  7. function resolve(dir) {
  8. return path.join(__dirname, './', dir)
  9. }
  10. const baseFolder = env.APPDATA !== undefined && env.APPDATA !== '' ? `${env.APPDATA}/ASP.NET/https` : `${env.HOME}/.aspnet/https`;
  11. const certificateName = 'ies.examserver.client';
  12. const certFilePath = path.join(baseFolder, `${certificateName}.pem`);
  13. const keyFilePath = path.join(baseFolder, `${certificateName}.key`);
  14. if (!fs.existsSync(baseFolder)) {
  15. fs.mkdirSync(baseFolder, { recursive: true });
  16. }
  17. if (!fs.existsSync(certFilePath) || !fs.existsSync(keyFilePath)) {
  18. if (0 !== require('child_process').spawnSync(
  19. 'dotnet',
  20. [
  21. 'dev-certs',
  22. 'https',
  23. '--export-path',
  24. certFilePath,
  25. '--format',
  26. 'Pem',
  27. '--no-password',
  28. ],
  29. { stdio: 'inherit' }
  30. ).status
  31. ) {
  32. throw new Error('Could not create certificate.');
  33. }
  34. }
  35. //const target = process.env.VUE_APP_API_BASE_URL || 'https://localhost:6001';
  36. module.exports = defineConfig({
  37. transpileDependencies: true,
  38. lintOnSave: false,
  39. devServer: {
  40. https: {
  41. key: fs.readFileSync(keyFilePath),
  42. cert: fs.readFileSync(certFilePath),
  43. },
  44. port: 8082,
  45. proxy: {
  46. /* '^/(.*)': {
  47. target,
  48. secure: false,
  49. changeOrigin: false,
  50. }, */
  51. '/api': {
  52. target: 'https://localhost:6001', //后端接口
  53. secure: false,
  54. changeOrigin: false,
  55. pathRewrite: {
  56. '^/api': ''
  57. }
  58. },
  59. '/package': {
  60. target: 'https://localhost:6001', //后端接口
  61. secure: false,
  62. changeOrigin: false,
  63. pathRewrite: {
  64. '^/package': '/package'
  65. }
  66. },
  67. '/script': {
  68. target: 'https://localhost:6001', //后端接口
  69. secure: false,
  70. changeOrigin: false,
  71. pathRewrite: {
  72. '^/script': '/script'
  73. }
  74. },
  75. },
  76. historyApiFallback: true,
  77. },
  78. })