Skip to content

Commit

Permalink
read tsconfig.json once at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcelhaney authored and LarsDenBakker committed Apr 29, 2022
1 parent d0232c5 commit 27f65da
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/dev-server-esbuild/src/EsbuildPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,20 @@ export class EsbuildPlugin implements Plugin {
private esbuildConfig: EsbuildConfig;
private logger?: Logger;
private transformedHtmlFiles: string[] = [];
private tsconfigRaw?: string;
name = 'esbuild';

constructor(esbuildConfig: EsbuildConfig) {
this.esbuildConfig = esbuildConfig;
}


async serverStart({ config, logger }: { config: DevServerCoreConfig; logger: Logger }) {
this.config = config;
this.logger = logger;
if (this.esbuildConfig.tsconfig) {
this.tsconfigRaw = await promisify(fs.readFile)(this.esbuildConfig.tsconfig, 'utf8');
}
}

resolveMimeType(context: Context) {
Expand Down Expand Up @@ -167,7 +172,6 @@ export class EsbuildPlugin implements Plugin {
): Promise<string> {
try {

const tsconfigRaw = this.esbuildConfig.tsconfig ? await promisify(fs.readFile)(this.esbuildConfig.tsconfig, 'utf8') : undefined;

const transformOptions: TransformOptions = {
sourcefile: filePath,
Expand All @@ -179,7 +183,7 @@ export class EsbuildPlugin implements Plugin {
jsxFactory: this.esbuildConfig.jsxFactory,
jsxFragment: this.esbuildConfig.jsxFragment,
define: this.esbuildConfig.define,
tsconfigRaw
tsconfigRaw: this.tsconfigRaw
};

const { code: transformedCode, warnings } = await transform(code, transformOptions);
Expand Down

0 comments on commit 27f65da

Please sign in to comment.