This commit is contained in:
2025-06-24 14:35:06 +08:00
parent 0878a4e6de
commit b48d14a6fb
6 changed files with 47 additions and 17 deletions

View File

@@ -0,0 +1,21 @@
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
}