blob: 97647bd82361afe01cb07db0180f2275fb36d072 [file] [log] [blame]
Takuto Ikuta2548a6c2022-02-01 12:10:021// Copyright 2022 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// @ts-check
6
7const path = require('path');
8
9const devtools_paths = require('../devtools_paths.js');
10const devtools_plugin = require('./devtools_plugin.js');
11
12// esbuild module uses binary in this path.
13process.env.ESBUILD_BINARY_PATH = path.join(devtools_paths.devtoolsRootPath(), 'third_party', 'esbuild', 'esbuild');
14
15const entryPoints = [process.argv[2]];
16const outfile = process.argv[3];
Simon Zünd69472202023-06-29 07:27:1317const useSourceMaps = process.argv.slice(4).includes('--configSourcemaps');
Takuto Ikuta2548a6c2022-02-01 12:10:0218
19const outdir = path.dirname(outfile);
20
21const plugin = {
22 name: 'devtools-plugin',
23 setup(build) {
24 // https://esbuild.github.io/plugins/#on-resolve
Takuto Ikutad0e51ea2022-02-08 02:06:4425 build.onResolve({filter: /.*/}, devtools_plugin.esbuildPlugin(outdir));
Takuto Ikuta2548a6c2022-02-01 12:10:0226 },
27};
28
29require('esbuild')
30 .build({
31 entryPoints,
32 outfile,
33 bundle: true,
34 format: 'esm',
35 platform: 'browser',
36 plugins: [plugin],
Simon Zünd69472202023-06-29 07:27:1337 sourcemap: useSourceMaps,
Takuto Ikuta2548a6c2022-02-01 12:10:0238 })
39 .catch(err => {
40 console.error('failed to run esbuild:', err);
41 process.exit(1);
42 });