Add public folder support
This commit is contained in:
1 parent
a02c7c71fe
commit
8a7c9bef0b
5 files changed
+37
-29
No files matched your search
+12
-1
@@ -4,6 +4,7 @@ import { build as viteBuild } from 'vite'
|
||||
import { build as electronBuild, Platform } from 'electron-builder'
|
||||
import { config as builderConfig } from '../configs/electron-builder.config.mjs'
|
||||
import chalk from 'chalk'
|
||||
import path from 'path'
|
||||
|
||||
const TAG = chalk.bgBlue('[build.mjs]')
|
||||
|
||||
@@ -16,7 +17,17 @@ const viteConfigs = {
|
||||
async function buildElectron() {
|
||||
for (const [name, configPath] of Object.entries(viteConfigs)) {
|
||||
console.group(TAG, name)
|
||||
await viteBuild({ configFile: configPath, mode: process.env.NODE_ENV })
|
||||
|
||||
const config = {
|
||||
configFile: configPath,
|
||||
mode: process.env.NODE_ENV,
|
||||
}
|
||||
|
||||
if (name === 'reactTs') {
|
||||
config.publicDir = path.resolve('./public')
|
||||
}
|
||||
|
||||
await viteBuild(config)
|
||||
console.groupEnd()
|
||||
console.log() // for beautiful log.
|
||||
}
|
||||
|
||||
+9
-8
@@ -1,14 +1,14 @@
|
||||
process.env.NODE_ENV = 'development'
|
||||
|
||||
import { readFileSync } from 'fs'
|
||||
import { join } from 'path'
|
||||
import { resolve, join } from 'path'
|
||||
import electron from 'electron'
|
||||
import { spawn } from 'child_process'
|
||||
import { createServer, build as viteBuild } from 'vite'
|
||||
import chalk from 'chalk'
|
||||
|
||||
const TAG = chalk.bgGreen('[dev.mjs]')
|
||||
const pkg = JSON.parse(readFileSync(join(process.cwd(), 'package.json'), 'utf8'))
|
||||
const pkg = JSON.parse(
|
||||
readFileSync(join(process.cwd(), 'package.json'), 'utf8')
|
||||
)
|
||||
|
||||
/**
|
||||
* @param {{ name: string; configFile: string; writeBundle: import('rollup').OutputPlugin['writeBundle'] }} param0
|
||||
@@ -22,9 +22,7 @@ function getWatcher({ name, configFile, writeBundle }) {
|
||||
watch: {},
|
||||
},
|
||||
configFile,
|
||||
plugins: [
|
||||
{ name, writeBundle },
|
||||
],
|
||||
plugins: [{ name, writeBundle }],
|
||||
})
|
||||
}
|
||||
|
||||
@@ -72,7 +70,10 @@ async function watchPreload(viteDevServer) {
|
||||
}
|
||||
|
||||
// bootstrap
|
||||
const viteDevServer = await createServer({ configFile: 'configs/vite.renderer.ts' })
|
||||
const viteDevServer = await createServer({
|
||||
configFile: 'configs/vite.renderer.ts',
|
||||
publicDir: resolve('./public'),
|
||||
})
|
||||
|
||||
await viteDevServer.listen()
|
||||
await watchPreload(viteDevServer)
|
||||
|
||||
Reference in new issue
Block a user