Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js.Build's externals option does not work for /assets #13183

Closed
rnwst opened this issue Dec 22, 2024 · 3 comments · Fixed by #13184
Closed

js.Build's externals option does not work for /assets #13183

rnwst opened this issue Dec 22, 2024 · 3 comments · Fixed by #13184
Assignees
Labels
Milestone

Comments

@rnwst
Copy link

rnwst commented Dec 22, 2024

Description and steps to reproduce

Under assets, I have a JS file script.js with contents

import '/external.js';

The file external.js has contents

console.log('This file should not be bundled!');

In my template, the script is included as follows:

{{- /* Make sure the resource "external.js" is published. */}}
{{- (resources.Get "external.js").Publish }}

{{- $script := resources.Get "script.js" }}
{{- $opts := dict "format" "esm"
                  "externals" (slice "/external.js")
}}
{{- $script = $script | js.Build $opts }}
  <script type="module" src="{{ $script.Permalink }}"></script>

Actual behaviour

The externals option seems to have no effect, and the file external.js is included in the bundled script.js. The bundled file looks as follows:

// ns-hugo-imp:/home/rnwst/src/hugo-test/assets/external.js
console.log("This file should not be bundled!");

Expected behaviour

external.js should not be bundled, and the import statement in script.js should be left untouched.

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.140.0+extended linux/amd64 BuildDate=unknown
@rnwst
Copy link
Author

rnwst commented Dec 22, 2024

I created a reproducing example here: https://github.com/rnwst/hugo-testing/tree/hugo-github-issue-13183

@bep bep changed the title js.Build's externals option does not work js.Build's externals option does not work for /assets Dec 22, 2024
@bep bep removed the NeedsTriage label Dec 22, 2024
@bep
Copy link
Member

bep commented Dec 22, 2024

I think I understand what's happening, and I suspect that this works fine for JS packages living in node_modules.

@rnwst
Copy link
Author

rnwst commented Dec 22, 2024

Amazing, thank you for fixing this so quickly! Everything is working as expected on latest master.

Hugo is an awesome project, thank you very much for all your hard work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants