const fs = require('fs') const { env } = require('process') const path = require('path') const { CleanWebpackPlugin } = require('clean-webpack-plugin') const { defineConfig } = require('@vue/cli-service') const Timestamp = new Date().getTime(); function resolve(dir) { return path.join(__dirname, './', dir) } const baseFolder = env.APPDATA !== undefined && env.APPDATA !== '' ? `${env.APPDATA}/ASP.NET/https` : `${env.HOME}/.aspnet/https`; const certificateName = 'ies.examserver.client'; const certFilePath = path.join(baseFolder, `${certificateName}.pem`); const keyFilePath = path.join(baseFolder, `${certificateName}.key`); if (!fs.existsSync(baseFolder)) { fs.mkdirSync(baseFolder, { recursive: true }); } if (!fs.existsSync(certFilePath) || !fs.existsSync(keyFilePath)) { if (0 !== require('child_process').spawnSync( 'dotnet', [ 'dev-certs', 'https', '--export-path', certFilePath, '--format', 'Pem', '--no-password', ], { stdio: 'inherit' } ).status ) { throw new Error('Could not create certificate.'); } } //const target = process.env.VUE_APP_API_BASE_URL || 'https://localhost:6001'; module.exports = defineConfig({ transpileDependencies: true, lintOnSave: false, devServer: { https: { key: fs.readFileSync(keyFilePath), cert: fs.readFileSync(certFilePath), }, port: 8082, proxy: { /* '^/(.*)': { target, secure: false, changeOrigin: false, }, */ '/api': { target: 'https://localhost:6001', //后端接口 secure: false, changeOrigin: false, pathRewrite: { '^/api': '' } }, '/package': { target: 'https://localhost:6001', //后端接口 secure: false, changeOrigin: false, pathRewrite: { '^/package': '/package' } }, '/script': { target: 'https://localhost:6001', //后端接口 secure: false, changeOrigin: false, pathRewrite: { '^/script': '/script' } }, }, historyApiFallback: true, }, })