| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import path from 'path';
- import vue from '@vitejs/plugin-vue';
- import { BilldHtmlWebpackPlugin, logData } from 'billd-html-webpack-plugin';
- import autoImport from 'unplugin-auto-import/vite';
- import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
- import unpluginVueComponents from 'unplugin-vue-components/vite';
- import { defineConfig } from 'vite';
- import checker from 'vite-plugin-checker';
- import eslint from 'vite-plugin-eslint2';
- import { createHtmlPlugin } from 'vite-plugin-html';
- import pkg from './package.json';
- // https://vitejs.dev/config/
- export default defineConfig(({ mode }) => {
- const isProduction = mode === 'production';
- const outputStaticUrl = () => {
- if (isProduction) {
- return 'https://live.hsslive.cn/dist/';
- } else {
- return './';
- }
- };
- return {
- base: outputStaticUrl(),
- css: {
- preprocessorOptions: {
- scss: {
- additionalData: `@use 'billd-scss/src/index.scss' as *;@import '@/assets/constant.scss';`,
- },
- },
- },
- resolve: {
- alias: { '@': path.resolve(__dirname, 'src') },
- /**
- * 不建议省略.vue后缀
- * https://cn.vitejs.dev/config/shared-options.html#resolve-extensions
- */
- // extensions: ['.js', '.ts', '.jsx', '.tsx', '.vue'],
- },
- build: {
- outDir: 'dist',
- },
- plugins: [
- // legacy(),
- // isProduction && legacy(),
- vue(),
- createHtmlPlugin({
- inject: {
- data: {
- // @ts-ignore
- title: '',
- },
- },
- }),
- checker({
- // typescript: true,
- vueTsc: true,
- // eslint: {
- // lintCommand: 'eslint "./src/**/*.{ts,tsx}"', // for example, lint .ts & .tsx
- // },
- }),
- eslint({}),
- autoImport({
- imports: [
- {
- 'naive-ui': ['useMessage', 'useNotification'],
- },
- ],
- }),
- unpluginVueComponents({
- // eslint-disable-next-line
- resolvers: [NaiveUiResolver()],
- }),
- new BilldHtmlWebpackPlugin({ env: 'vite4' }).config,
- ],
- define: {
- 'process.env': {
- BilldHtmlWebpackPlugin: logData(null),
- NODE_ENV: JSON.stringify(isProduction ? 'production' : 'development'),
- PUBLIC_PATH: outputStaticUrl(),
- VUE_APP_RELEASE_PROJECT_NAME: JSON.stringify(
- process.env.VUE_APP_RELEASE_PROJECT_NAME
- ),
- VUE_APP_RELEASE_PROJECT_ENV: JSON.stringify(
- process.env.VUE_APP_RELEASE_PROJECT_ENV
- ),
- VUE_APP_RELEASE_PROJECT_VERSION: JSON.stringify(pkg.version),
- },
- },
- server: {
- host: '0.0.0.0',
- proxy: {
- '/api': {
- target: 'http://localhost:4300',
- secure: false, // 默认情况下(secure: true),不接受在HTTPS上运行的带有无效证书的后端服务器。设置secure: false后,后端服务器的HTTPS有无效证书也可运行
- /**
- * changeOrigin,是否修改请求地址的源
- * 默认changeOrigin: false,即发请求即使用devServer的localhost:port发起的,如果后端服务器有校验源,就会有问题
- * 设置changeOrigin: true,就会修改发起请求的源,将原本的localhost:port修改为target,这样就可以通过后端服务器对源的校验
- */
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/api/, '/'),
- },
- '/betaapi': {
- target: 'http://localhost:4300',
- secure: false, // 默认情况下(secure: true),不接受在HTTPS上运行的带有无效证书的后端服务器。设置secure: false后,后端服务器的HTTPS有无效证书也可运行
- /**
- * changeOrigin,是否修改请求地址的源
- * 默认changeOrigin: false,即发请求即使用devServer的localhost:port发起的,如果后端服务器有校验源,就会有问题
- * 设置changeOrigin: true,就会修改发起请求的源,将原本的localhost:port修改为target,这样就可以通过后端服务器对源的校验
- */
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/betaapi/, '/'),
- },
- '/prodapi': {
- target: 'http://localhost:4200',
- secure: false, // 默认情况下(secure: true),不接受在HTTPS上运行的带有无效证书的后端服务器。设置secure: false后,后端服务器的HTTPS有无效证书也可运行
- /**
- * changeOrigin,是否修改请求地址的源
- * 默认changeOrigin: false,即发请求即使用devServer的localhost:port发起的,如果后端服务器有校验源,就会有问题
- * 设置changeOrigin: true,就会修改发起请求的源,将原本的localhost:port修改为target,这样就可以通过后端服务器对源的校验
- */
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/prodapi/, '/'),
- },
- },
- },
- };
- });
|