Skip to content

Commit c4d93ab

Browse files
committed
fix(ci): Disable unnecessary SCSS processing when building JS assets.
- Build resources if not cached - Ensure node_modules dependencies are available for asset processing - Be more precise in the template when building assets in production mode and avoid conflicts with SCSS and CSS processing. - Ignore node_modules when loading source maps - Add .vscode/launch.json with debugging configuration for localhost:1313. In VSCode, go to Run and select the site to launch Chrome, connect to Developer Tools, and start debugging.
1 parent 03fbbf6 commit c4d93ab

File tree

4 files changed

+103
-31
lines changed

4 files changed

+103
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ node_modules
2121
test-results.xml
2222
/influxdb3cli-build-scripts/content
2323
.vscode/*
24+
!.vscode/launch.json
2425
.idea
2526
**/config.toml
2627
package-lock.json

.vscode/launch.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "chrome",
9+
"request": "launch",
10+
"name": "Open Docs on localhost:1313",
11+
"url": "http://localhost:1313",
12+
"webRoot": "${workspaceFolder}",
13+
"skipFiles": [
14+
"<node_internals>/**",
15+
"${workspaceFolder}/node_modules/**"
16+
]
17+
}
18+
]
19+
}

config/production/config.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,25 @@ minify:
1616
# Production asset processing
1717
build:
1818
writeStats: false
19-
useResourceCacheWhen: "always"
19+
useResourceCacheWhen: "fallback"
2020
buildOptions:
2121
sourcemap: false
2222
target: "es2015"
2323

24+
# Asset processing configuration
25+
assetDir: "assets"
26+
27+
# Mount assets for production
28+
module:
29+
mounts:
30+
- source: assets
31+
target: assets
32+
- source: node_modules
33+
target: assets/node_modules
34+
2435
# Disable development server settings
25-
server: {}
36+
server: {}
37+
38+
# Suppress the warning mentioned in the error
39+
ignoreLogs:
40+
- 'warning-goldmark-raw-html'

layouts/partials/header/javascript.html

Lines changed: 66 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<!-- Get site data -->
66
<!-- Load cloudUrls array -->
77
{{ $cloudUrls := slice }}
8-
{{- range.Site.Data.influxdb_urls.cloud.providers }}
9-
{{- range.regions }}
10-
{{ $cloudUrls = $cloudUrls | append "{{ safeHTML .url }}" }}
8+
{{- range .Site.Data.influxdb_urls.cloud.providers }}
9+
{{- range .regions }}
10+
{{ $cloudUrls = $cloudUrls | append (safeHTML .url) }}
1111
{{ end -}}
1212
{{ end -}}
1313
{{ $products := .Site.Data.products }}
@@ -16,55 +16,92 @@
1616
{{ $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) }}
1717

1818
{{ if $isDevelopmentOrTesting }}
19-
{{/* Load individual JS files for debugging */}}
19+
{{/* Load individual JS files for debugging with ESM format */}}
2020
{{ $sharedParams := dict "product" $product "currentVersion" $currentVersion "isServer" hugo.IsServer "products" $products "influxdb_urls" $influxdb_urls "cloudUrls" $cloudUrls }}
2121

2222
{{/* Load main.js first to ensure proper initialization */}}
23-
{{ with resources.Get "js/main.js" }}
23+
{{ $mainJS := resources.Get "js/main.js" }}
24+
{{ if $mainJS }}
2425
{{ $opts := dict
2526
"minify" false
26-
"sourceMap" "inline"
27+
"sourceMap" "external"
2728
"targetPath" "js/main.js"
2829
"params" $sharedParams
30+
"format" "esm"
31+
"external" (slice "*")
32+
"define" (dict
33+
"process.env.NODE_ENV" "\"development\""
34+
)
35+
"splitting" false
36+
"bundle" true
2937
}}
30-
{{ with . | js.Build $opts }}
31-
<script defer src="{{ .RelPermalink }}"></script>
38+
{{ $processed := $mainJS | js.Build $opts }}
39+
{{ if $processed }}
40+
<script type="module" src="{{ $processed.RelPermalink }}"></script>
3241
{{ end }}
3342
{{ end }}
3443

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>
44+
{{/* Load other individual JS files for debugging with error handling */}}
45+
{{ $jsDir := "assets/js" }}
46+
{{ if fileExists $jsDir }}
47+
{{ range $file := (readDir $jsDir) }}
48+
{{ if and (strings.HasSuffix $file.Name ".js") (ne $file.Name "main.js") }}
49+
{{ $jsPath := printf "js/%s" $file.Name }}
50+
{{ $jsResource := resources.Get $jsPath }}
51+
{{ if $jsResource }}
52+
{{ $opts := dict
53+
"minify" false
54+
"sourceMap" "external"
55+
"targetPath" $jsPath
56+
"params" $sharedParams
57+
"format" "esm"
58+
"external" (slice "*")
59+
"define" (dict
60+
"process.env.NODE_ENV" "\"development\""
61+
)
62+
"splitting" false
63+
"bundle" true
64+
}}
65+
{{ $processed := $jsResource | js.Build $opts }}
66+
{{ if $processed }}
67+
<script type="module" src="{{ $processed.RelPermalink }}"></script>
68+
{{ end }}
4869
{{ end }}
4970
{{ end }}
5071
{{ end }}
5172
{{ end }}
5273
{{ else }}
53-
{{/* Non-development environment: Bundle everything */}}
54-
{{ with resources.Get "js/main.js" }}
74+
{{/* Production environment: Use IIFE for better compatibility */}}
75+
{{ $mainJS := resources.Get "js/main.js" }}
76+
{{ if $mainJS }}
77+
{{ $sharedParams := dict "product" $product "currentVersion" $currentVersion "isServer" hugo.IsServer "products" $products "influxdb_urls" $influxdb_urls "cloudUrls" $cloudUrls }}
78+
5579
{{ $opts := dict
5680
"minify" hugo.IsProduction
57-
"sourceMap" (cond hugo.IsProduction "" "external")
81+
"sourceMap" ""
5882
"targetPath" "js/main.js"
59-
"params" (dict "product" $product "currentVersion" $currentVersion "isServer" hugo.IsServer "products" $products "influxdb_urls" $influxdb_urls "cloudUrls" $cloudUrls)
83+
"params" $sharedParams
84+
"format" "iife"
85+
"splitting" false
86+
"external" (slice "*")
87+
"define" (dict
88+
"process.env.NODE_ENV" "\"production\""
89+
)
6090
}}
61-
{{ with . | js.Build $opts }}
91+
92+
{{ $processed := "" }}
93+
{{ with $mainJS }}
94+
{{ $processed = . | js.Build $opts }}
95+
{{ end }}
96+
97+
{{ if $processed }}
6298
{{ if hugo.IsProduction }}
63-
{{ with . | fingerprint }}
64-
<script defer src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"></script>
99+
{{ $fingerprinted := $processed | fingerprint }}
100+
{{ if $fingerprinted }}
101+
<script defer src="{{ $fingerprinted.RelPermalink }}" integrity="{{ $fingerprinted.Data.Integrity }}" crossorigin="anonymous"></script>
65102
{{ end }}
66103
{{ else }}
67-
<script defer src="{{ .RelPermalink }}"></script>
104+
<script defer src="{{ $processed.RelPermalink }}"></script>
68105
{{ end }}
69106
{{ end }}
70107
{{ end }}

0 commit comments

Comments
 (0)