From b09122e1b31d3ed766d6c6aa046f46de62d3bbba Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Sun, 13 Oct 2024 15:24:35 +0800 Subject: [PATCH] feat(theme): improve loading config file (#276) --- theme/src/node/loadConfig/compiler.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/theme/src/node/loadConfig/compiler.ts b/theme/src/node/loadConfig/compiler.ts index e2fcac9e..6d12c567 100644 --- a/theme/src/node/loadConfig/compiler.ts +++ b/theme/src/node/loadConfig/compiler.ts @@ -24,16 +24,19 @@ export async function compiler(configPath?: string, entryPoints: [configPath], outfile: 'out.js', write: false, - target: ['node18'], + target: [`node${process.versions.node}`], platform: 'node', bundle: true, format: 'esm', + mainFields: ['main'], sourcemap: 'inline', metafile: true, define: { '__dirname': dirnameVarName, '__filename': filenameVarName, 'import.meta.url': importMetaUrlVarName, + 'import.meta.dirname': dirnameVarName, + 'import.meta.filename': filenameVarName, }, plugins: [ { @@ -52,7 +55,7 @@ export async function compiler(configPath?: string, name: 'inject-file-scope-variables', setup(build) { build.onLoad({ filter: /\.[cm]?[jt]s$/ }, async (args) => { - const contents = await fsp.readFile(args.path, 'utf8') + const contents = await fsp.readFile(args.path, 'utf-8') const injectValues = `const ${dirnameVarName} = ${JSON.stringify( path.dirname(args.path),