2022-04-13 16:17:21 +08:00
|
|
|
/// <reference types="vitest" />
|
2023-01-07 14:39:03 +08:00
|
|
|
import react from '@vitejs/plugin-react-swc'
|
2022-03-29 16:52:53 +08:00
|
|
|
import dotenv from 'dotenv'
|
2023-01-24 16:29:33 +08:00
|
|
|
import { join } from 'path'
|
2022-03-29 16:52:53 +08:00
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
|
|
|
|
import { visualizer } from 'rollup-plugin-visualizer'
|
2022-06-08 11:48:22 +08:00
|
|
|
import { VitePWA } from 'vite-plugin-pwa'
|
2022-08-22 16:51:23 +08:00
|
|
|
import filenamesToType from './vitePluginFilenamesToType'
|
2023-01-07 14:39:03 +08:00
|
|
|
import { appName } from './utils/const'
|
2022-03-29 16:52:53 +08:00
|
|
|
|
2023-01-24 16:29:33 +08:00
|
|
|
dotenv.config({ path: join(__dirname, '../../.env') })
|
2022-05-29 17:53:27 +08:00
|
|
|
const IS_ELECTRON = process.env.IS_ELECTRON
|
|
|
|
|
2022-03-29 16:52:53 +08:00
|
|
|
/**
|
|
|
|
* @see https://vitejs.dev/config/
|
|
|
|
*/
|
|
|
|
export default defineConfig({
|
2022-06-14 23:23:34 +08:00
|
|
|
clearScreen: IS_ELECTRON ? false : true,
|
2022-03-29 16:52:53 +08:00
|
|
|
mode: process.env.NODE_ENV,
|
2022-05-12 02:45:43 +08:00
|
|
|
root: './',
|
2022-05-29 17:53:27 +08:00
|
|
|
base: '/',
|
2022-06-14 23:23:34 +08:00
|
|
|
resolve: {
|
|
|
|
alias: {
|
2023-01-07 14:39:03 +08:00
|
|
|
'@': join(__dirname, '..'),
|
2022-06-14 23:23:34 +08:00
|
|
|
},
|
|
|
|
},
|
2022-03-29 16:52:53 +08:00
|
|
|
plugins: [
|
|
|
|
react(),
|
2022-08-22 16:51:23 +08:00
|
|
|
filenamesToType([
|
|
|
|
{
|
|
|
|
dictionary: './assets/icons',
|
|
|
|
typeFile: './components/Icon/iconNamesType.ts',
|
|
|
|
},
|
|
|
|
]),
|
2022-03-29 16:52:53 +08:00
|
|
|
|
2022-06-08 11:48:22 +08:00
|
|
|
/**
|
|
|
|
* @see https://vite-plugin-pwa.netlify.app/guide/generate.html
|
|
|
|
*/
|
2023-01-24 16:29:33 +08:00
|
|
|
VitePWA({
|
|
|
|
registerType: 'autoUpdate',
|
|
|
|
manifest: {
|
|
|
|
name: appName,
|
|
|
|
short_name: appName,
|
|
|
|
description: 'Description of your app',
|
|
|
|
theme_color: '#000',
|
|
|
|
icons: [
|
|
|
|
{
|
|
|
|
src: 'pwa-192x192.png',
|
|
|
|
sizes: '192x192',
|
|
|
|
type: 'image/png',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
src: 'pwa-512x512.png',
|
|
|
|
sizes: '512x512',
|
|
|
|
type: 'image/png',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
src: 'pwa-512x512.png',
|
|
|
|
sizes: '512x512',
|
|
|
|
type: 'image/png',
|
|
|
|
purpose: 'any maskable',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
}),
|
2022-06-08 11:48:22 +08:00
|
|
|
|
2022-03-29 16:52:53 +08:00
|
|
|
/**
|
|
|
|
* @see https://github.com/vbenjs/vite-plugin-svg-icons
|
|
|
|
*/
|
|
|
|
createSvgIconsPlugin({
|
2022-05-12 02:45:43 +08:00
|
|
|
iconDirs: [join(__dirname, './assets/icons')],
|
2022-03-29 16:52:53 +08:00
|
|
|
symbolId: 'icon-[name]',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
build: {
|
2022-05-29 17:53:27 +08:00
|
|
|
target: IS_ELECTRON ? 'esnext' : 'modules',
|
2022-05-12 17:53:04 +08:00
|
|
|
sourcemap: true,
|
2022-05-12 02:45:43 +08:00
|
|
|
outDir: './dist',
|
2022-03-29 16:52:53 +08:00
|
|
|
emptyOutDir: true,
|
|
|
|
rollupOptions: {
|
|
|
|
plugins: [
|
2023-01-07 14:39:03 +08:00
|
|
|
// visualizer({
|
|
|
|
// filename: './bundle-stats.html',
|
|
|
|
// gzipSize: true,
|
|
|
|
// projectRoot: './',
|
|
|
|
// template: 'treemap',
|
|
|
|
// }),
|
2022-03-29 16:52:53 +08:00
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
server: {
|
2023-01-24 16:29:33 +08:00
|
|
|
port: Number(process.env.ELECTRON_WEB_SERVER_PORT || 42710),
|
2022-05-29 17:53:27 +08:00
|
|
|
strictPort: IS_ELECTRON ? true : false,
|
2022-03-29 16:52:53 +08:00
|
|
|
proxy: {
|
|
|
|
'/netease/': {
|
2023-01-07 14:39:03 +08:00
|
|
|
target: `http://127.0.0.1:${process.env.ELECTRON_DEV_NETEASE_API_PORT || 30001}`,
|
2022-03-29 16:52:53 +08:00
|
|
|
changeOrigin: true,
|
2022-05-29 17:53:27 +08:00
|
|
|
rewrite: path => (IS_ELECTRON ? path : path.replace(/^\/netease/, '')),
|
2022-03-29 16:52:53 +08:00
|
|
|
},
|
2023-01-24 16:29:33 +08:00
|
|
|
'/r3play/': {
|
2023-01-07 14:39:03 +08:00
|
|
|
target: `http://127.0.0.1:${process.env.ELECTRON_DEV_NETEASE_API_PORT || 30001}`,
|
2022-03-29 16:52:53 +08:00
|
|
|
changeOrigin: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-06-08 11:48:22 +08:00
|
|
|
preview: {
|
2023-01-24 16:29:33 +08:00
|
|
|
port: Number(process.env.ELECTRON_WEB_SERVER_PORT || 42710),
|
2022-06-08 11:48:22 +08:00
|
|
|
},
|
2022-04-13 16:17:21 +08:00
|
|
|
test: {
|
|
|
|
environment: 'jsdom',
|
|
|
|
},
|
2022-03-29 16:52:53 +08:00
|
|
|
})
|