From c4d93ab24939e42b5cc59c7ff86687c3e80ff705 Mon Sep 17 00:00:00 2001 From: Jason Stirnaman Date: Tue, 3 Jun 2025 11:23:34 -0500 Subject: [PATCH] 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. --- .gitignore | 1 + .vscode/launch.json | 19 +++++ config/production/config.yml | 19 ++++- layouts/partials/header/javascript.html | 95 +++++++++++++++++-------- 4 files changed, 103 insertions(+), 31 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.gitignore b/.gitignore index 650f31962..d34fa2f89 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ node_modules test-results.xml /influxdb3cli-build-scripts/content .vscode/* +!.vscode/launch.json .idea **/config.toml package-lock.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..b98c9b2f4 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,19 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "chrome", + "request": "launch", + "name": "Open Docs on localhost:1313", + "url": "http://localhost:1313", + "webRoot": "${workspaceFolder}", + "skipFiles": [ + "/**", + "${workspaceFolder}/node_modules/**" + ] + } + ] +} \ No newline at end of file diff --git a/config/production/config.yml b/config/production/config.yml index 0dc30871b..da574daff 100644 --- a/config/production/config.yml +++ b/config/production/config.yml @@ -16,10 +16,25 @@ minify: # Production asset processing build: writeStats: false - useResourceCacheWhen: "always" + useResourceCacheWhen: "fallback" buildOptions: sourcemap: false target: "es2015" +# Asset processing configuration +assetDir: "assets" + +# Mount assets for production +module: + mounts: + - source: assets + target: assets + - source: node_modules + target: assets/node_modules + # Disable development server settings -server: {} \ No newline at end of file +server: {} + +# Suppress the warning mentioned in the error +ignoreLogs: + - 'warning-goldmark-raw-html' \ No newline at end of file diff --git a/layouts/partials/header/javascript.html b/layouts/partials/header/javascript.html index bb45dee8f..ea855ae8b 100644 --- a/layouts/partials/header/javascript.html +++ b/layouts/partials/header/javascript.html @@ -5,9 +5,9 @@ {{ $cloudUrls := slice }} -{{- range.Site.Data.influxdb_urls.cloud.providers }} - {{- range.regions }} - {{ $cloudUrls = $cloudUrls | append "{{ safeHTML .url }}" }} +{{- range .Site.Data.influxdb_urls.cloud.providers }} + {{- range .regions }} + {{ $cloudUrls = $cloudUrls | append (safeHTML .url) }} {{ end -}} {{ end -}} {{ $products := .Site.Data.products }} @@ -16,55 +16,92 @@ {{ $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) }} {{ if $isDevelopmentOrTesting }} - {{/* Load individual JS files for debugging */}} + {{/* Load individual JS files for debugging with ESM format */}} {{ $sharedParams := dict "product" $product "currentVersion" $currentVersion "isServer" hugo.IsServer "products" $products "influxdb_urls" $influxdb_urls "cloudUrls" $cloudUrls }} {{/* Load main.js first to ensure proper initialization */}} - {{ with resources.Get "js/main.js" }} + {{ $mainJS := resources.Get "js/main.js" }} + {{ if $mainJS }} {{ $opts := dict "minify" false - "sourceMap" "inline" + "sourceMap" "external" "targetPath" "js/main.js" "params" $sharedParams + "format" "esm" + "external" (slice "*") + "define" (dict + "process.env.NODE_ENV" "\"development\"" + ) + "splitting" false + "bundle" true }} - {{ with . | js.Build $opts }} - + {{ $processed := $mainJS | js.Build $opts }} + {{ if $processed }} + {{ end }} {{ end }} - {{/* Load other individual JS files for debugging */}} - {{ range $file := (readDir "assets/js") }} - {{ if and (strings.HasSuffix $file.Name ".js") (ne $file.Name "main.js") }} - {{ $jsPath := printf "js/%s" $file.Name }} - {{ with resources.Get $jsPath }} - {{ $opts := dict - "minify" false - "sourceMap" "inline" - "targetPath" $jsPath - "params" $sharedParams - }} - {{ with . | js.Build $opts }} - + {{/* Load other individual JS files for debugging with error handling */}} + {{ $jsDir := "assets/js" }} + {{ if fileExists $jsDir }} + {{ range $file := (readDir $jsDir) }} + {{ if and (strings.HasSuffix $file.Name ".js") (ne $file.Name "main.js") }} + {{ $jsPath := printf "js/%s" $file.Name }} + {{ $jsResource := resources.Get $jsPath }} + {{ if $jsResource }} + {{ $opts := dict + "minify" false + "sourceMap" "external" + "targetPath" $jsPath + "params" $sharedParams + "format" "esm" + "external" (slice "*") + "define" (dict + "process.env.NODE_ENV" "\"development\"" + ) + "splitting" false + "bundle" true + }} + {{ $processed := $jsResource | js.Build $opts }} + {{ if $processed }} + + {{ end }} {{ end }} {{ end }} {{ end }} {{ end }} {{ else }} - {{/* Non-development environment: Bundle everything */}} - {{ with resources.Get "js/main.js" }} + {{/* Production environment: Use IIFE for better compatibility */}} + {{ $mainJS := resources.Get "js/main.js" }} + {{ if $mainJS }} + {{ $sharedParams := dict "product" $product "currentVersion" $currentVersion "isServer" hugo.IsServer "products" $products "influxdb_urls" $influxdb_urls "cloudUrls" $cloudUrls }} + {{ $opts := dict "minify" hugo.IsProduction - "sourceMap" (cond hugo.IsProduction "" "external") + "sourceMap" "" "targetPath" "js/main.js" - "params" (dict "product" $product "currentVersion" $currentVersion "isServer" hugo.IsServer "products" $products "influxdb_urls" $influxdb_urls "cloudUrls" $cloudUrls) + "params" $sharedParams + "format" "iife" + "splitting" false + "external" (slice "*") + "define" (dict + "process.env.NODE_ENV" "\"production\"" + ) }} - {{ with . | js.Build $opts }} + + {{ $processed := "" }} + {{ with $mainJS }} + {{ $processed = . | js.Build $opts }} + {{ end }} + + {{ if $processed }} {{ if hugo.IsProduction }} - {{ with . | fingerprint }} - + {{ $fingerprinted := $processed | fingerprint }} + {{ if $fingerprinted }} + {{ end }} {{ else }} - + {{ end }} {{ end }} {{ end }}