Skip to content

Commit 13129c5

Browse files
committed
chore(js): Unbundle assets in Hugo development and testing environments:
- Keep assets unbundled for easier debugging in development and testing. - Copies other config from development to testing.
1 parent c43df75 commit 13129c5

File tree

6 files changed

+217
-26
lines changed

6 files changed

+217
-26
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- /home/circleci/bin
4242
- run:
4343
name: Hugo Build
44-
command: npx hugo --logLevel info --minify --destination workspace/public
44+
command: npx hugo --config config/production/config.yml --logLevel info --minify --destination workspace/public
4545
- persist_to_workspace:
4646
root: workspace
4747
paths:

config/production/config.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Production overrides for CI/CD builds
2+
baseURL: 'https://docs.influxdata.com/'
3+
4+
# Production environment parameters
5+
params:
6+
env: production
7+
environment: production
8+
9+
# Enable minification for production
10+
minify:
11+
disableJS: false
12+
disableCSS: false
13+
disableHTML: false
14+
minifyOutput: true
15+
16+
# Production asset processing
17+
build:
18+
writeStats: false
19+
useResourceCacheWhen: "always"
20+
buildOptions:
21+
sourcemap: false
22+
target: "es2015"
23+
24+
# Disable development server settings
25+
server: {}

config/testing/config.yml

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,111 @@
11
baseURL: 'http://localhost:1315/'
2+
languageCode: en-us
3+
title: InfluxDB Documentation
24

3-
server:
4-
port: 1315
5+
# Git history information for lastMod-type functionality
6+
enableGitInfo: true
7+
8+
# Syntax Highlighting
9+
pygmentsCodefences: true
10+
pygmentsUseClasses: true
11+
12+
# Preserve case in article tags
13+
preserveTaxonomyNames: true
14+
15+
# Generate a robots.txt
16+
enableRobotsTXT: true
517

618
# Override settings for testing
719
buildFuture: true
820

921
# Configure what content is built in testing env
1022
params:
23+
env: testing
1124
environment: testing
1225
buildTestContent: true
13-
26+
27+
# Server configuration for testing
28+
server:
29+
port: 1315
30+
baseURL: 'http://localhost:1315/'
31+
watchChanges: true
32+
disableLiveReload: false
33+
1434
# Keep your shared content exclusions
1535
ignoreFiles:
1636
- "content/shared/.*"
1737

1838
# Ignore specific warning logs
1939
ignoreLogs:
20-
- warning-goldmark-raw-html
40+
- warning-goldmark-raw-html
41+
42+
# Markdown rendering options
43+
blackfriday:
44+
hrefTargetBlank: true
45+
smartDashes: false
46+
47+
# Copy taxonomies from main config
48+
taxonomies:
49+
influxdb/v2/tag: influxdb/v2/tags
50+
influxdb/cloud/tag: influxdb/cloud/tags
51+
influxdb3/cloud-serverless/tag: influxdb/cloud-serverless/tags
52+
influxdb3/cloud-dedicated/tag: influxdb/cloud-dedicated/tags
53+
influxdb3/clustered/tag: influxdb3/clustered/tags
54+
influxdb3/core/tag: influxdb3/core/tags
55+
influxdb3/enterprise/tag: influxdb3/enterprise/tags
56+
flux/v0/tag: flux/v0/tags
57+
58+
# Markup configuration
59+
markup:
60+
goldmark:
61+
renderer:
62+
unsafe: true
63+
extensions:
64+
linkify: false
65+
parser:
66+
attribute:
67+
block: true
68+
69+
# Privacy settings
70+
privacy:
71+
googleAnalytics:
72+
anonymizeIP: false
73+
disable: false
74+
respectDoNotTrack: true
75+
useSessionStorage: false
76+
youtube:
77+
disable: false
78+
privacyEnhanced: true
79+
80+
# Output formats
81+
outputFormats:
82+
json:
83+
mediaType: application/json
84+
baseName: pages
85+
isPlainText: true
86+
87+
# Asset processing for testing (disable minification)
88+
build:
89+
writeStats: true
90+
useResourceCacheWhen: "fallback"
91+
buildOptions:
92+
sourcemap: "inline"
93+
target: "es2020"
94+
95+
# Disable minification for testing
96+
minify:
97+
disableJS: true
98+
disableCSS: true
99+
disableHTML: true
100+
minifyOutput: false
101+
102+
# Asset processing configuration
103+
assetDir: "assets"
104+
105+
# Module mounts
106+
module:
107+
mounts:
108+
- source: assets
109+
target: assets
110+
- source: node_modules
111+
target: assets/node_modules

hugo.staging.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,26 @@ enableRobotsTXT: true
1717

1818
# Custom staging params
1919
params:
20+
env: staging
2021
environment: staging
22+
server:
23+
disableLiveReload: true
24+
25+
# Staging uses the same asset processing as production
26+
# Enable minification for staging
27+
minify:
28+
disableJS: false
29+
disableCSS: false
30+
disableHTML: false
31+
minifyOutput: true
32+
33+
# Staging asset processing
34+
build:
35+
writeStats: false
36+
useResourceCacheWhen: "always"
37+
buildOptions:
38+
sourcemap: false
39+
target: "es2015"
2140

2241
# Markdown rendering options
2342
blackfriday:

hugo.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,16 @@ outputFormats:
5555
baseName: pages
5656
isPlainText: true
5757

58+
# Asset processing configuration for development
5859
build:
59-
# Configure JavaScript build settings for ES6 modules
6060
writeStats: true
6161
useResourceCacheWhen: "fallback"
62+
# Enable source maps for debugging
63+
buildOptions:
64+
sourcemap: "inline"
65+
target: "es2020"
66+
# Disable asset bundling in development
67+
noJSConfigInAssets: false
6268

6369
# Asset processing configuration
6470
assetDir: "assets"
@@ -70,11 +76,22 @@ module:
7076
- source: node_modules
7177
target: assets/node_modules
7278

73-
# Ensure proper JavaScript processing in development
79+
# Development settings
80+
params:
81+
env: development
82+
environment: development
83+
84+
# Configure the server for development
85+
# Specify the port for development to avoid conflicts with testing
86+
server:
87+
port: 1313
88+
baseURL: 'http://localhost:1313/'
89+
watchChanges: true
90+
disableLiveReload: false
91+
92+
# Disable minification and bundling for development
7493
minify:
7594
disableJS: true
95+
disableCSS: true
96+
disableHTML: true
7697
minifyOutput: false
77-
78-
# Development settings
79-
params:
80-
env: development

layouts/partials/header/javascript.html

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,60 @@
1212
{{ end -}}
1313
{{ $products := .Site.Data.products }}
1414
{{ $influxdb_urls := .Site.Data.influxdb_urls }}
15-
<!-- Build index.js -->
16-
{{ with resources.Get "js/main.js" }}
17-
{{ $opts := dict
18-
"minify" hugo.IsProduction
19-
"sourceMap" (cond hugo.IsProduction "" "external")
20-
"targetPath" "js/main.js"
21-
"params" (dict "product" $product "currentVersion" $currentVersion "isServer" hugo.IsServer "products" $products "influxdb_urls" $influxdb_urls "cloudUrls" $cloudUrls)
22-
}}
23-
{{ with . | js.Build $opts }}
24-
{{ if hugo.IsProduction }}
25-
{{ with . | fingerprint }}
26-
<script defer src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"></script>
27-
{{ end }}
28-
{{ else }}
15+
16+
{{ $isDevelopmentOrTesting := or (eq .Site.Params.environment "development") (eq .Site.Params.environment "testing") (eq (getenv "HUGO_ENV") "development") (eq (getenv "HUGO_ENV") "testing") (not hugo.IsProduction) }}
17+
18+
{{ if $isDevelopmentOrTesting }}
19+
{{/* Load individual JS files for debugging */}}
20+
{{ $sharedParams := dict "product" $product "currentVersion" $currentVersion "isServer" hugo.IsServer "products" $products "influxdb_urls" $influxdb_urls "cloudUrls" $cloudUrls }}
21+
22+
{{/* Load main.js first to ensure proper initialization */}}
23+
{{ with resources.Get "js/main.js" }}
24+
{{ $opts := dict
25+
"minify" false
26+
"sourceMap" "inline"
27+
"targetPath" "js/main.js"
28+
"params" $sharedParams
29+
}}
30+
{{ with . | js.Build $opts }}
2931
<script defer src="{{ .RelPermalink }}"></script>
3032
{{ end }}
3133
{{ end }}
32-
{{ end }}
34+
35+
{{/* Load other individual JS files for debugging */}}
36+
{{ range $file := (readDir "assets/js") }}
37+
{{ if and (strings.HasSuffix $file.Name ".js") (ne $file.Name "main.js") }}
38+
{{ $jsPath := printf "js/%s" $file.Name }}
39+
{{ with resources.Get $jsPath }}
40+
{{ $opts := dict
41+
"minify" false
42+
"sourceMap" "inline"
43+
"targetPath" $jsPath
44+
"params" $sharedParams
45+
}}
46+
{{ with . | js.Build $opts }}
47+
<script defer src="{{ .RelPermalink }}"></script>
48+
{{ end }}
49+
{{ end }}
50+
{{ end }}
51+
{{ end }}
52+
{{ else }}
53+
{{/* Non-development environment: Bundle everything */}}
54+
{{ with resources.Get "js/main.js" }}
55+
{{ $opts := dict
56+
"minify" hugo.IsProduction
57+
"sourceMap" (cond hugo.IsProduction "" "external")
58+
"targetPath" "js/main.js"
59+
"params" (dict "product" $product "currentVersion" $currentVersion "isServer" hugo.IsServer "products" $products "influxdb_urls" $influxdb_urls "cloudUrls" $cloudUrls)
60+
}}
61+
{{ with . | js.Build $opts }}
62+
{{ if hugo.IsProduction }}
63+
{{ with . | fingerprint }}
64+
<script defer src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"></script>
65+
{{ end }}
66+
{{ else }}
67+
<script defer src="{{ .RelPermalink }}"></script>
68+
{{ end }}
69+
{{ end }}
70+
{{ end }}
71+
{{ end }}

0 commit comments

Comments
 (0)