1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const esbuild_1 = require("esbuild");
|
4 | class ESBuildPlugin {
|
5 | apply(compiler) {
|
6 | let watching = false;
|
7 | const safeStartService = async () => {
|
8 | if (!compiler.$esbuildService) {
|
9 | compiler.$esbuildService = await esbuild_1.startService();
|
10 | }
|
11 | };
|
12 | compiler.hooks.thisCompilation.tap('esbuild', compilation => {
|
13 | compilation.hooks.childCompiler.tap('esbuild', childCompiler => {
|
14 | childCompiler.$esbuildService = compiler.$esbuildService;
|
15 | });
|
16 | });
|
17 | compiler.hooks.run.tapPromise('esbuild', async () => {
|
18 | await safeStartService();
|
19 | });
|
20 | compiler.hooks.watchRun.tapPromise('esbuild', async () => {
|
21 | watching = true;
|
22 | await safeStartService();
|
23 | });
|
24 | compiler.hooks.done.tap('esbuild', () => {
|
25 | if (!watching && compiler.$esbuildService) {
|
26 | compiler.$esbuildService.stop();
|
27 | compiler.$esbuildService = undefined;
|
28 | }
|
29 | });
|
30 | }
|
31 | }
|
32 | exports.default = ESBuildPlugin;
|