// 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
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)
Target: target,
Format: format,
+ Platform: platform,
Sourcemap: sourceMap,
SourcesContent: sourcesContent,
Bundle: true,
Target: api.ESNext,
Format: api.FormatIIFE,
+ Platform: api.PlatformBrowser,
SourcesContent: 1,
Stdin: &api.StdinOptions{
Loader: api.LoaderJS,
Bundle: true,
Target: api.ES2018,
Format: api.FormatCommonJS,
+ Platform: api.PlatformBrowser,
SourcesContent: 1,
MinifyIdentifiers: true,
MinifySyntax: true,
Bundle: true,
Target: api.ES2018,
Format: api.FormatCommonJS,
+ Platform: api.PlatformBrowser,
MinifyIdentifiers: true,
MinifySyntax: true,
MinifyWhitespace: true,
Bundle: true,
Target: api.ES2018,
Format: api.FormatCommonJS,
+ Platform: api.PlatformBrowser,
MinifyIdentifiers: true,
MinifySyntax: true,
MinifyWhitespace: true,
Bundle: true,
Target: api.ES2018,
Format: api.FormatCommonJS,
+ Platform: api.PlatformBrowser,
MinifyIdentifiers: true,
MinifySyntax: true,
MinifyWhitespace: true,
Bundle: true,
Target: api.ESNext,
Format: api.FormatIIFE,
+ Platform: api.PlatformBrowser,
SourcesContent: 1,
Stdin: &api.StdinOptions{
Loader: api.LoaderJS,
func TestDecodeExternalOptions(t *testing.T) {
c := qt.New(t)
- m := map[string]any{}
- opts, err := DecodeExternalOptions(m)
+ m := map[string]any{
+ "platform": "node",
+ }
+ ext, err := DecodeExternalOptions(m)
c.Assert(err, qt.IsNil)
- c.Assert(opts, qt.DeepEquals, ExternalOptions{
+ c.Assert(ext, qt.DeepEquals, ExternalOptions{
SourcesContent: true,
+ Platform: "node",
+ })
+
+ opts := Options{
+ ExternalOptions: ext,
+ }
+ c.Assert(opts.compile(), qt.IsNil)
+ c.Assert(opts.compiled, qt.DeepEquals, api.BuildOptions{
+ Bundle: true,
+ Target: api.ESNext,
+ Format: api.FormatIIFE,
+ Platform: api.PlatformNode,
+ SourcesContent: api.SourcesContentInclude,
})
}