{{ $defines := dict "process.env.NODE_ENV" `"development"` }}
```
+##### drop
+
+Edit your source code before building to drop certain constructs: One of `debugger` or `console`.
+
+{{< new-in 0.144.0 />}}
+
+See https://esbuild.github.io/api/#drop
+
###### sourceMap
(`string`) Whether to generate `inline`, `linked` or `external` source maps from esbuild. Linked and external source maps will be written to the target with the output file name + ".map". When `linked` a `sourceMappingURL` will also be written to the output file. By default, source maps are not created. Note that the `linked` option was added in Hugo 0.140.0.
// User defined symbols.
Defines map[string]any
+ // This tells esbuild to edit your source code before building to drop certain constructs.
+ // See https://esbuild.github.io/api/#drop
+ Drop string
+
// Maps a component import to another.
Shims map[string]string
defines = maps.ToStringMapString(opts.Defines)
}
+ var drop api.Drop
+ switch opts.Drop {
+ case "":
+ case "console":
+ drop = api.DropConsole
+ case "debugger":
+ drop = api.DropDebugger
+ default:
+ err = fmt.Errorf("unsupported drop type: %q", opts.Drop)
+ }
+
// By default we only need to specify outDir and no outFile
outDir := opts.OutDir
outFile := ""
Define: defines,
External: opts.Externals,
+ Drop: drop,
JSXFactory: opts.JSXFactory,
JSXFragment: opts.JSXFragment,
JSX: api.JSXAutomatic,
JSXImportSource: "preact",
})
+
+ opts = Options{
+ ExternalOptions: ExternalOptions{
+ Drop: "console",
+ },
+ }
+ c.Assert(opts.compile(), qt.IsNil)
+ c.Assert(opts.compiled.Drop, qt.Equals, api.DropConsole)
+ opts = Options{
+ ExternalOptions: ExternalOptions{
+ Drop: "debugger",
+ },
+ }
+ c.Assert(opts.compile(), qt.IsNil)
+ c.Assert(opts.compiled.Drop, qt.Equals, api.DropDebugger)
+
+ opts = Options{
+ ExternalOptions: ExternalOptions{
+ Drop: "adsfadsf",
+ },
+ }
+ c.Assert(opts.compile(), qt.ErrorMatches, `unsupported drop type: "adsfadsf"`)
}
func TestToBuildOptionsTarget(t *testing.T) {