从webpack迁移到vite

This commit is contained in:
lyswhut
2023-08-07 18:49:14 +08:00
parent 31e16a7ed7
commit 028bf5919d
166 changed files with 3071 additions and 11869 deletions
+77
View File
@@ -0,0 +1,77 @@
import path from 'node:path'
import type { UserConfig } from 'vite'
import { builtinModules } from 'node:module'
const isProd = process.env.NODE_ENV == 'production'
const rootPath = path.join(__dirname, '../../../')
const config: UserConfig = {
mode: process.env.NODE_ENV == 'production' ? 'production' : 'development',
root: path.join(rootPath, 'src/main'),
base: './',
publicDir: false,
logLevel: 'warn',
resolve: {
alias: {
'@root': path.join(rootPath, 'src'),
'@common': path.join(rootPath, 'src/common'),
'@static': path.join(__dirname, 'src/static'),
'@main': path.join(rootPath, 'src/main'),
},
browserField: false,
},
build: {
lib: {
entry: `${isProd ? 'index.ts' : 'index-dev.ts'}`,
formats: ['cjs'],
fileName: 'main',
},
outDir: path.join(rootPath, 'dist/main'),
emptyOutDir: true,
reportCompressedSize: false,
modulePreload: false,
// assetsDir: 'chunks',
minify: false,
watch: {
buildDelay: 500,
},
commonjsOptions: {
dynamicRequireTargets: ['*.js'],
ignoreDynamicRequires: true,
},
rollupOptions: {
external: [
'electron',
'better-sqlite3',
'font-list',
'electron-font-manager',
...builtinModules.flatMap(m => [m, `node:${m}`]),
],
input: {
main: `src/main/${isProd ? 'index.ts' : 'index-dev.ts'}`,
'dbService.worker': 'src/main/worker/dbService/index.ts',
},
output: {
entryFileNames: '[name].js',
chunkFileNames: '[name].js',
format: 'cjs',
// manualChunks(id, info) {
// // return 'main'
// },
experimentalMinChunkSize: 50_000,
},
logLevel: 'warn',
},
},
define: {
'process.env.NODE_ENV': `"${process.env.NODE_ENV as string}"`,
__STATIC_PATH__: `"${path.join(rootPath, 'src/static').replace(/\\/g, '\\\\')}"`,
__USER_API_PATH__: `"${path.join(rootPath, 'src/main/modules/userApi').replace(/\\/g, '\\\\')}"`,
__QRC_DECODE_NODE_PATH__: `"${(isProd ? '../../build/Release' : path.join(rootPath, 'build/Release')).replace(/\\/g, '\\\\')}"`,
},
cacheDir: path.join(rootPath, 'node_modules/.vite/main'),
}
export default config
@@ -0,0 +1,28 @@
// const autoprefixer = require('autoprefixer')
const pxtorem = require('postcss-pxtorem')
module.exports = {
plugins: [
pxtorem({
rootValue: 16,
unitPrecision: 5,
propList: [
'font', 'font-size',
'letter-spacing',
'padding', 'margin',
'padding-*', 'margin-*',
'height', 'width',
'*-height', '*-width',
'flex', '::-webkit-scrollbar',
'top', 'left', 'bottom', 'right',
'border-radius', 'gap',
],
selectorBlackList: ['html', 'ignore-to-rem'],
replace: true,
mediaQuery: false,
minPixelValue: 0,
exclude: [/node_modules/i],
}),
// autoprefixer(),
],
}
@@ -0,0 +1,74 @@
import path from 'node:path'
import type { UserConfig } from 'vite'
import { builtinModules } from 'node:module'
import vue from '@vitejs/plugin-vue'
import renderer from 'vite-plugin-electron-renderer'
import postcssConfig from './postcss.config'
// const isProd = process.env.NODE_ENV == 'production'
const rootPath = path.join(__dirname, '../../../')
const external = ['electron', ...builtinModules.flatMap(m => [m, `node:${m}`])]
const config: UserConfig = {
mode: process.env.NODE_ENV == 'production' ? 'production' : 'development',
root: path.join(rootPath, 'src/renderer-lyric'),
base: './',
publicDir: false,
logLevel: 'warn',
resolve: {
alias: {
'@root': path.join(rootPath, 'src'),
'@common': path.join(rootPath, 'src/common'),
'@static': path.join(__dirname, 'src/static'),
'@lyric': path.join(rootPath, 'src/renderer-lyric'),
},
browserField: true,
},
plugins: [vue(), renderer()],
build: {
target: 'esnext',
outDir: path.join(rootPath, 'dist/renderer-lyric'),
modulePreload: false,
emptyOutDir: true,
reportCompressedSize: false,
assetsDir: './',
// assetsDir: 'chunks',
minify: false,
watch: {
buildDelay: 500,
},
rollupOptions: {
external,
input: {
'renderer-lyric': 'src/renderer-lyric/index.html',
},
output: {
entryFileNames: '[name].js',
format: 'cjs',
// manualChunks(id, info) {
// return 'renderer'
// },
experimentalMinChunkSize: 50_000,
},
logLevel: 'warn',
},
},
css: {
postcss: postcssConfig,
},
optimizeDeps: {
include: [],
},
define: {
'process.env.NODE_ENV': `"${process.env.NODE_ENV as string}"`,
'process.env.ELECTRON_DISABLE_SECURITY_WARNINGS': 'true',
__STATIC_PATH__: `"${path.join(rootPath, 'src/static').replace(/\\/g, '\\\\')}"`,
},
server: {
port: 9081,
},
cacheDir: path.join(rootPath, 'node_modules/.vite/renderer-lyric'),
}
export default config
@@ -0,0 +1,61 @@
import path from 'node:path'
import type { UserConfig } from 'vite'
import { builtinModules } from 'node:module'
// const isProd = process.env.NODE_ENV == 'production'
const rootPath = path.join(__dirname, '../../../')
const config: UserConfig = {
mode: process.env.NODE_ENV,
root: path.join(rootPath, 'src/main'),
base: './',
publicDir: false,
logLevel: 'warn',
resolve: {
alias: {
'@root': path.join(rootPath, 'src'),
'@common': path.join(rootPath, 'src/common'),
'@static': path.join(__dirname, 'src/static'),
},
browserField: true,
},
build: {
lib: {
entry: 'modules/userApi/renderer/preload.js',
formats: ['cjs'],
fileName: 'user-api-preload',
},
outDir: path.join(rootPath, 'dist/preload'),
modulePreload: {
polyfill: false,
},
emptyOutDir: true,
reportCompressedSize: false,
// assetsDir: 'chunks',
minify: false,
watch: {
buildDelay: 500,
},
rollupOptions: {
external: ['electron', ...builtinModules.flatMap(m => [m, `node:${m}`])],
input: {
'user-api-preload': 'src/main/modules/userApi/renderer/preload.js',
},
output: {
entryFileNames: '[name].js',
// manualChunks(id, info) {
// // return 'main'
// },
experimentalMinChunkSize: 50_000,
},
logLevel: 'warn',
},
},
define: {
'process.env.NODE_ENV': `"${process.env.NODE_ENV as string}"`,
__STATIC_PATH__: `"${path.join(rootPath, 'src/static').replace(/\\/g, '\\\\')}"`,
},
cacheDir: path.join(rootPath, 'node_modules/.vite/scripts'),
}
export default config
+105
View File
@@ -0,0 +1,105 @@
import path from 'node:path'
import type { UserConfig } from 'vite'
import { builtinModules } from 'node:module'
import vue from '@vitejs/plugin-vue'
import renderer from 'vite-plugin-electron-renderer'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import postcssConfig from './postcss.config'
const isProd = process.env.NODE_ENV == 'production'
const rootPath = path.join(__dirname, '../../../')
const external = ['electron', ...builtinModules.flatMap(m => [m, `node:${m}`])]
const config: UserConfig = {
mode: process.env.NODE_ENV == 'production' ? 'production' : 'development',
root: path.join(rootPath, 'src/renderer'),
base: './',
publicDir: isProd ? false : path.join(rootPath, 'src/common/theme'),
logLevel: 'warn',
resolve: {
alias: {
'@root': path.join(rootPath, 'src'),
'@common': path.join(rootPath, 'src/common'),
'@static': path.join(__dirname, 'src/static'),
'@renderer': path.join(rootPath, 'src/renderer'),
},
browserField: true,
},
plugins: [
vue(),
renderer(),
createSvgIconsPlugin({
iconDirs: [path.join(rootPath, 'src/renderer/assets/svgs')],
}),
],
build: {
target: 'esnext',
outDir: path.join(rootPath, 'dist/renderer'),
modulePreload: false,
emptyOutDir: true,
reportCompressedSize: false,
// assetsDir: 'chunks',
assetsDir: './',
minify: false,
watch: {
buildDelay: 500,
},
rollupOptions: {
external,
input: {
renderer: 'src/renderer/index.html',
},
output: {
entryFileNames: '[name].js',
format: 'cjs',
experimentalMinChunkSize: 50_000,
// manualChunks: {
// 'iconv-lite': ['iconv-lite'],
// },
},
logLevel: 'warn',
},
commonjsOptions: {
include: [
/vendors/,
/node_modules/,
/utils\/musicMeta/,
],
},
},
css: {
postcss: postcssConfig,
},
optimizeDeps: {
// // exclude: [],
include: [
'@common/utils/musicMeta',
'@renderer/utils/musicSdk/kg/vendors/infSign.min',
],
},
define: {
'process.env.NODE_ENV': `"${process.env.NODE_ENV as string}"`,
'process.env.ELECTRON_DISABLE_SECURITY_WARNINGS': 'true',
__STATIC_PATH__: `"${path.join(rootPath, 'src/static').replace(/\\/g, '\\\\')}"`,
},
server: {
port: 9080,
},
worker: {
plugins: [renderer()],
rollupOptions: {
output: {
// entryFileNames: '[name].js',
inlineDynamicImports: true,
format: 'iife',
experimentalMinChunkSize: 50_000,
},
logLevel: 'warn',
},
// format: 'es',
},
cacheDir: path.join(rootPath, 'node_modules/.vite/renderer'),
}
export default config