Skip to content

Commit

Permalink
feat(theme): improve loading config file (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo authored Oct 13, 2024
1 parent c4025cb commit b09122e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions theme/src/node/loadConfig/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand All @@ -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),
Expand Down

0 comments on commit b09122e

Please sign in to comment.