Takuto Ikuta | 2548a6c | 2022-02-01 12:10:02 | [diff] [blame] | 1 | // 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 | |
| 7 | const path = require('path'); |
| 8 | |
| 9 | const devtools_paths = require('../devtools_paths.js'); |
| 10 | const devtools_plugin = require('./devtools_plugin.js'); |
| 11 | |
| 12 | // esbuild module uses binary in this path. |
| 13 | process.env.ESBUILD_BINARY_PATH = path.join(devtools_paths.devtoolsRootPath(), 'third_party', 'esbuild', 'esbuild'); |
| 14 | |
| 15 | const entryPoints = [process.argv[2]]; |
| 16 | const outfile = process.argv[3]; |
Simon Zünd | 6947220 | 2023-06-29 07:27:13 | [diff] [blame] | 17 | const useSourceMaps = process.argv.slice(4).includes('--configSourcemaps'); |
Takuto Ikuta | 2548a6c | 2022-02-01 12:10:02 | [diff] [blame] | 18 | |
| 19 | const outdir = path.dirname(outfile); |
| 20 | |
| 21 | const plugin = { |
| 22 | name: 'devtools-plugin', |
| 23 | setup(build) { |
| 24 | // https://esbuild.github.io/plugins/#on-resolve |
Takuto Ikuta | d0e51ea | 2022-02-08 02:06:44 | [diff] [blame] | 25 | build.onResolve({filter: /.*/}, devtools_plugin.esbuildPlugin(outdir)); |
Takuto Ikuta | 2548a6c | 2022-02-01 12:10:02 | [diff] [blame] | 26 | }, |
| 27 | }; |
| 28 | |
| 29 | require('esbuild') |
| 30 | .build({ |
| 31 | entryPoints, |
| 32 | outfile, |
| 33 | bundle: true, |
| 34 | format: 'esm', |
| 35 | platform: 'browser', |
| 36 | plugins: [plugin], |
Simon Zünd | 6947220 | 2023-06-29 07:27:13 | [diff] [blame] | 37 | sourcemap: useSourceMaps, |
Takuto Ikuta | 2548a6c | 2022-02-01 12:10:02 | [diff] [blame] | 38 | }) |
| 39 | .catch(err => { |
| 40 | console.error('failed to run esbuild:', err); |
| 41 | process.exit(1); |
| 42 | }); |