From 16917388d1003aa66418b810990ef0102b4f95c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7?= <308487730@qq.com> Date: Fri, 7 Jan 2022 08:44:55 +0800 Subject: [PATCH] Use module.createRequire instead fs.readFile for import package.json --- scripts/watch.mjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/watch.mjs b/scripts/watch.mjs index 195fee9..a0b86ff 100644 --- a/scripts/watch.mjs +++ b/scripts/watch.mjs @@ -1,14 +1,14 @@ process.env.NODE_ENV = 'development' -import { readFileSync } from 'fs' -import { join } from 'path' import electron from 'electron' import { spawn } from 'child_process' +import { createRequire } from 'module' 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 require = createRequire(import.meta.url) +const pkg = require('../package.json') /** * @param {{ name: string; configFile: string; writeBundle: import('rollup').OutputPlugin['writeBundle'] }} param0