js/esbuild: Add platform option

Closes #13136
This commit is contained in:
Bjørn Erik Pedersen
2024-12-12 22:09:59 +01:00
parent 75ad9cdaab
commit ec1933f79d
2 changed files with 43 additions and 3 deletions

View File

@@ -121,6 +121,11 @@ type ExternalOptions struct {
// Default is to esm.
Format string
// One of browser, node, neutral.
// Default is browser.
// See https://esbuild.github.io/api/#platform
Platform string
// External dependencies, e.g. "react".
Externals []string
@@ -274,6 +279,19 @@ func (opts *Options) compile() (err error) {
return
}
var platform api.Platform
switch opts.Platform {
case "", "browser":
platform = api.PlatformBrowser
case "node":
platform = api.PlatformNode
case "neutral":
platform = api.PlatformNeutral
default:
err = fmt.Errorf("unsupported platform type: %q", opts.Platform)
return
}
var defines map[string]string
if opts.Defines != nil {
defines = maps.ToStringMapString(opts.Defines)
@@ -310,6 +328,7 @@ func (opts *Options) compile() (err error) {
Target: target,
Format: format,
Platform: platform,
Sourcemap: sourceMap,
SourcesContent: sourcesContent,