22 lines
414 B
Go
22 lines
414 B
Go
package js
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/evanw/esbuild/pkg/api"
|
|
)
|
|
|
|
func Compress(js string) (string, error) {
|
|
result := api.Transform(js, api.TransformOptions{
|
|
Loader: api.LoaderJS,
|
|
MinifyWhitespace: true,
|
|
MinifyIdentifiers: true,
|
|
MinifySyntax: true,
|
|
})
|
|
|
|
if len(result.Errors) > 0 {
|
|
return "", fmt.Errorf("js compress error: %v", result.Errors)
|
|
}
|
|
return string(result.Code), nil
|
|
}
|