-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathminfy.go
More file actions
27 lines (22 loc) · 681 Bytes
/
minfy.go
File metadata and controls
27 lines (22 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright 2022 - Offen Authors <hioffen@posteo.de>
// SPDX-License-Identifier: Apache-2.0
package consent
import (
"fmt"
"os"
esbuild "github.com/evanw/esbuild/pkg/api"
)
func minifyJS(js string) (string, error) {
_, isDevelopment := os.LookupEnv("DEVELOPMENT")
result := esbuild.Transform(js, esbuild.TransformOptions{
MinifyWhitespace: !isDevelopment,
MinifyIdentifiers: !isDevelopment,
MinifySyntax: !isDevelopment,
Target: esbuild.ES2015,
Format: esbuild.FormatIIFE,
})
if len(result.Errors) != 0 {
return "", fmt.Errorf("minifyJS: error minifying script: %s", result.Errors[0].Text)
}
return string(result.Code), nil
}