mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-28 14:40:43 +03:00
parent
75ad9cdaab
commit
ec1933f79d
2 changed files with 43 additions and 3 deletions
|
@ -121,6 +121,11 @@ type ExternalOptions struct {
|
||||||
// Default is to esm.
|
// Default is to esm.
|
||||||
Format string
|
Format string
|
||||||
|
|
||||||
|
// One of browser, node, neutral.
|
||||||
|
// Default is browser.
|
||||||
|
// See https://esbuild.github.io/api/#platform
|
||||||
|
Platform string
|
||||||
|
|
||||||
// External dependencies, e.g. "react".
|
// External dependencies, e.g. "react".
|
||||||
Externals []string
|
Externals []string
|
||||||
|
|
||||||
|
@ -274,6 +279,19 @@ func (opts *Options) compile() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var platform api.Platform
|
||||||
|
switch opts.Platform {
|
||||||
|
case "", "browser":
|
||||||
|
platform = api.PlatformBrowser
|
||||||
|
case "node":
|
||||||
|
platform = api.PlatformNode
|
||||||
|
case "neutral":
|
||||||
|
platform = api.PlatformNeutral
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("unsupported platform type: %q", opts.Platform)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var defines map[string]string
|
var defines map[string]string
|
||||||
if opts.Defines != nil {
|
if opts.Defines != nil {
|
||||||
defines = maps.ToStringMapString(opts.Defines)
|
defines = maps.ToStringMapString(opts.Defines)
|
||||||
|
@ -310,6 +328,7 @@ func (opts *Options) compile() (err error) {
|
||||||
|
|
||||||
Target: target,
|
Target: target,
|
||||||
Format: format,
|
Format: format,
|
||||||
|
Platform: platform,
|
||||||
Sourcemap: sourceMap,
|
Sourcemap: sourceMap,
|
||||||
SourcesContent: sourcesContent,
|
SourcesContent: sourcesContent,
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ func TestToBuildOptions(t *testing.T) {
|
||||||
Bundle: true,
|
Bundle: true,
|
||||||
Target: api.ESNext,
|
Target: api.ESNext,
|
||||||
Format: api.FormatIIFE,
|
Format: api.FormatIIFE,
|
||||||
|
Platform: api.PlatformBrowser,
|
||||||
SourcesContent: 1,
|
SourcesContent: 1,
|
||||||
Stdin: &api.StdinOptions{
|
Stdin: &api.StdinOptions{
|
||||||
Loader: api.LoaderJS,
|
Loader: api.LoaderJS,
|
||||||
|
@ -62,6 +63,7 @@ func TestToBuildOptions(t *testing.T) {
|
||||||
Bundle: true,
|
Bundle: true,
|
||||||
Target: api.ES2018,
|
Target: api.ES2018,
|
||||||
Format: api.FormatCommonJS,
|
Format: api.FormatCommonJS,
|
||||||
|
Platform: api.PlatformBrowser,
|
||||||
SourcesContent: 1,
|
SourcesContent: 1,
|
||||||
MinifyIdentifiers: true,
|
MinifyIdentifiers: true,
|
||||||
MinifySyntax: true,
|
MinifySyntax: true,
|
||||||
|
@ -87,6 +89,7 @@ func TestToBuildOptions(t *testing.T) {
|
||||||
Bundle: true,
|
Bundle: true,
|
||||||
Target: api.ES2018,
|
Target: api.ES2018,
|
||||||
Format: api.FormatCommonJS,
|
Format: api.FormatCommonJS,
|
||||||
|
Platform: api.PlatformBrowser,
|
||||||
MinifyIdentifiers: true,
|
MinifyIdentifiers: true,
|
||||||
MinifySyntax: true,
|
MinifySyntax: true,
|
||||||
MinifyWhitespace: true,
|
MinifyWhitespace: true,
|
||||||
|
@ -113,6 +116,7 @@ func TestToBuildOptions(t *testing.T) {
|
||||||
Bundle: true,
|
Bundle: true,
|
||||||
Target: api.ES2018,
|
Target: api.ES2018,
|
||||||
Format: api.FormatCommonJS,
|
Format: api.FormatCommonJS,
|
||||||
|
Platform: api.PlatformBrowser,
|
||||||
MinifyIdentifiers: true,
|
MinifyIdentifiers: true,
|
||||||
MinifySyntax: true,
|
MinifySyntax: true,
|
||||||
MinifyWhitespace: true,
|
MinifyWhitespace: true,
|
||||||
|
@ -139,6 +143,7 @@ func TestToBuildOptions(t *testing.T) {
|
||||||
Bundle: true,
|
Bundle: true,
|
||||||
Target: api.ES2018,
|
Target: api.ES2018,
|
||||||
Format: api.FormatCommonJS,
|
Format: api.FormatCommonJS,
|
||||||
|
Platform: api.PlatformBrowser,
|
||||||
MinifyIdentifiers: true,
|
MinifyIdentifiers: true,
|
||||||
MinifySyntax: true,
|
MinifySyntax: true,
|
||||||
MinifyWhitespace: true,
|
MinifyWhitespace: true,
|
||||||
|
@ -164,6 +169,7 @@ func TestToBuildOptions(t *testing.T) {
|
||||||
Bundle: true,
|
Bundle: true,
|
||||||
Target: api.ESNext,
|
Target: api.ESNext,
|
||||||
Format: api.FormatIIFE,
|
Format: api.FormatIIFE,
|
||||||
|
Platform: api.PlatformBrowser,
|
||||||
SourcesContent: 1,
|
SourcesContent: 1,
|
||||||
Stdin: &api.StdinOptions{
|
Stdin: &api.StdinOptions{
|
||||||
Loader: api.LoaderJS,
|
Loader: api.LoaderJS,
|
||||||
|
@ -210,10 +216,25 @@ func TestToBuildOptionsTarget(t *testing.T) {
|
||||||
|
|
||||||
func TestDecodeExternalOptions(t *testing.T) {
|
func TestDecodeExternalOptions(t *testing.T) {
|
||||||
c := qt.New(t)
|
c := qt.New(t)
|
||||||
m := map[string]any{}
|
m := map[string]any{
|
||||||
opts, err := DecodeExternalOptions(m)
|
"platform": "node",
|
||||||
|
}
|
||||||
|
ext, err := DecodeExternalOptions(m)
|
||||||
c.Assert(err, qt.IsNil)
|
c.Assert(err, qt.IsNil)
|
||||||
c.Assert(opts, qt.DeepEquals, ExternalOptions{
|
c.Assert(ext, qt.DeepEquals, ExternalOptions{
|
||||||
SourcesContent: true,
|
SourcesContent: true,
|
||||||
|
Platform: "node",
|
||||||
|
})
|
||||||
|
|
||||||
|
opts := Options{
|
||||||
|
ExternalOptions: ext,
|
||||||
|
}
|
||||||
|
c.Assert(opts.compile(), qt.IsNil)
|
||||||
|
c.Assert(opts.compiled, qt.DeepEquals, api.BuildOptions{
|
||||||
|
Bundle: true,
|
||||||
|
Target: api.ESNext,
|
||||||
|
Format: api.FormatIIFE,
|
||||||
|
Platform: api.PlatformNode,
|
||||||
|
SourcesContent: api.SourcesContentInclude,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue