-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
ESBuild supports "import *.css" in js file but needs outDir as option for js.Build #8411
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
Comments
This is my first time contributing and I have only been going through the source code for a few hours. I have determined that esbuild is creating the css output file but only if the outputDir has been set, which only occurs when sourceMapExternal is used (the outputDir is never set otherwise which results in esbuild defaulting to WriteToStdOut = true, which throws the error above. Here are some output values from this test: {{ $js := resources.Get "script.js" | js.Build (dict "sourceMap" "external" ) }} TargetPath: I do not know how the context determines the output file and I see there is a separate function for publishing the external map. I am assuming that something similar can be adapted for the css file. Although the whole function may need to be fixed to avoid future issues with other esbuild feature improvements or changes. Not sure, but I am posting this in case it helps anyone work on this issue. |
What do you use these CSS imports for? |
Hey Bjørn,
I encountered the issue when attempting to use fullcalendar.io. The
calendar requires a css file to display correctly and I believe it also has
functions that allow the user to change the style.
Matt
…On Thu, Apr 15, 2021, 8:42 AM Bjørn Erik Pedersen ***@***.***> wrote:
What do you use these CSS imports for?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#8411 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEWYX3CWIJ5MY4H2CPYSMGTTI3NMJANCNFSM422L75NQ>
.
|
Sure, but why not just import the CSS in the HTML? I say this because there are several issues that need to be understood before we can do this:
So, your PR looks fine and would work for many, but I'm not prepared to merge that at the moment. |
As a workaround, I can comment out the import in the module itself, copy the css file to the static folder and import it in the html, but that would only work for me and I may forget to do that if I clone and build my repository elsewhere. Esbuild would handle the css files; however, it is still a work in progress over there and may not work correctly. If I have two node_modules importing css files, esbuild would concatenate those files into a single css file, but esbuild does not yet support css modules as per their website, so if two files both contain, for instance, So I agree that we wait on the merge but it will have to be addressed in the future or users will be unable to use js.Build with any node_module that has an "import .css" line. Also, thanks for the quick responses and all the work you put into this project! |
I have thought a little about this, and I think if we could get these 2 items to work, it would be a good first step:
We can discuss the rest in the PR. |
So, because Hugo does not set an My suggestion to solve the issue would be to include a js.Build option, such as "cssFileName." If left blank, Hugo can, by default, either not create the css file generated by ESBuild or export it in the same way that ESBuild does (i.e. script.js and script.css). I hope this makes the issue more clear. Also, sorry about delay on response. I took some time to read through the full Hugo resource transformers sections so that I would (hopefully) have a better understanding of the whole system. Anyways, let me know how you think we should proceed and then I will modify the pull request. I didn't think the issues section was the place to continue this discussion so I created a discourse topic. For whenever you have time: https://discourse.gohugo.io/t/hugo-integration-with-js-build-esbuild-and-multiple-output-files/32647?u=ghostt8117 |
I have encountered this issue when trying to use the This would make it easy to configure Prism via {
"plugins": [
["prismjs", {
"languages": ["javascript", "css", "markup"],
"plugins": ["line-numbers"],
"theme": "twilight",
"css": true
}]
]
} The plugin optionally includes the theme's CSS. The CSS is included via This means I need to explicitly include the plugin and theme CSS which defeats the purpose of using the plugin. |
Any updates on this? |
Also curious for an update. Any chance this will get changed in the near term? I'm currently having to fall back to webpack for everything, simply because so much JS in the ecosystem imports a css file somewhere. I'd much rather use Hugo pipes! |
I am hitting this with the adobe coral-spectrum packages. |
…but because of gohugoio/hugo#8411 must because of css including issues
In answer to an earlier question, you would want to import the CSS with javascript instead of in the HTML to support light and dark modes that cleanly affect the javascript components. Using the adobe coral-spectrum packages as an example, I would import different css theme files if the site switches from light to dark mode. |
What version of Hugo are you using (
hugo version
)?Does this issue reproduce with the latest release?
Yes
As per esbuild:
This is not currently supported with js.Build and results in an error with modules that include an import in the javascript file.
error: Cannot import "entry.css" into a JavaScript file without an output path configured
The text was updated successfully, but these errors were encountered: