mirror of
https://github.com/LukeHagar/electron-vite.git
synced 2025-12-10 12:27:44 +00:00
feat: static asset handling
This commit is contained in:
11
src/utils.ts
11
src/utils.ts
@@ -1,4 +1,6 @@
|
||||
import { URL, URLSearchParams } from 'node:url'
|
||||
import path from 'node:path'
|
||||
import { createHash } from 'node:crypto'
|
||||
import { loadEnv as viteLoadEnv } from 'vite'
|
||||
|
||||
export function isObject(value: unknown): value is Record<string, unknown> {
|
||||
@@ -26,6 +28,15 @@ export function parseRequest(id: string): Record<string, string> | null {
|
||||
return Object.fromEntries(new URLSearchParams(search))
|
||||
}
|
||||
|
||||
export function getHash(text: Buffer | string): string {
|
||||
return createHash('sha256').update(text).digest('hex').substring(0, 8)
|
||||
}
|
||||
|
||||
export function toRelativePath(filename: string, importer: string): string {
|
||||
const relPath = path.posix.relative(path.dirname(importer), filename)
|
||||
return relPath.startsWith('.') ? relPath : `./${relPath}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Load `.env` files within the `envDir`(default: `process.cwd()`).
|
||||
* By default, only env variables prefixed with `MAIN_VITE_`, `PRELOAD_VITE_` and
|
||||
|
||||
Reference in New Issue
Block a user