---
title: js.Build
description: Bundles, transpiles, tree shakes, and minifies JavaScript resources.
weight: 30
categories: []
keywords: []
action:
aliases: []
related:
- functions/js/Babel
- functions/resources/Fingerprint
- functions/resources/Minify
returnType: resource.Resource
signatures: ['js.Build [OPTIONS] RESOURCE']
toc: true
---
The `js.Build` function uses the [evanw/esbuild] package to:
- Bundle
- Transpile (TypeScript and JSX)
- Tree shake
- Minify
- Create source maps
[evanw/esbuild]: https://github.com/evanw/esbuild
```go-html-template
{{ with resources.Get "js/main.js" }}
{{ if hugo.IsDevelopment }}
{{ with . | js.Build }}
{{ end }}
{{ else }}
{{ $opts := dict "minify" true }}
{{ with . | js.Build $opts | fingerprint }}
{{ end }}
{{ end }}
{{ end }}
```
## Options
targetPath
: (`string`) If not set, the source path will be used as the base target path.
Note that the target path's extension may change if the target MIME type is different, e.g. when the source is TypeScript.
format
: (`string`) The output format. One of: `iife`, `cjs`, `esm`. Default is `iife`, a self-executing function, suitable for inclusion as a `
```