Open erke-soptim opened 2 months ago
This is probably due to webpack minifying css js html files and probably other too to lower the bundle size when building your site.
What is your usecase with these js files in the static folder ?
Static files should never be changed. They could be example code that's downloaded. I thought there's a similar issue but I can't find it now.
Ah, https://github.com/facebook/docusaurus/issues/10334 should be similar. Perhaps they are the same issue.
Static files should never be changed.
That is what I understood from the docs saying that none of the files in the static folder will be post-processed, hashed, or minified.
They could be example code that's downloaded. I thought there's a similar issue but I can't find it now.
That is exactly what we are trying to achieve. We have a bunch of code snippets in the static
folder that users can view and download. So, naturally, we would like to preserve how those are formatted.
Perhaps related to https://github.com/facebook/docusaurus/issues/10334 "Docusaurus 3.4.0+ does not respect PostCSS plugins when it minimizes CSS files from 'static' folder". The bullet-proof approach is to leave the static resources intact.
As mentioned above, JS and CSS files in the static folder are getting minified since Docusaurus 3.4.
In our case, we put API reference files in the static
folder, which include JS scripts and CSS styles generated by document generators such as Dokka, Jazzy, and the like. In one particular case, the minified assets are actually causing an issue where display of API reference is broken, which shows up properly in the build with Docusaurs 3.3.2 or lower.
In conclusion, I agree with @soptim-erke and @hrumhurum's comments on leaving the static resources intact.
After upgrading to latest docusaurus (3.1.1 to 3.5.2) I also experienced this issue. We have a static folder full of pre-built code that is now altered after running docusaurus build
(the issue is not there when running with docusaurus start
). I noticed that something messed up the CSS in the static folder causing weird issues.
For people also experiencing this: I found that using the workaround (outlined in https://github.com/facebook/docusaurus/issues/10334) by setting USE_SIMPLE_CSS_MINIFIER=true
fixes my issue.
It's probably not the right fix, as static resources should be left intact and unaltered (as stated in this issue thread already) but it does the job for my use case.
Have you read the Contributing Guidelines on issues?
Prerequisites
npm run clear
oryarn clear
command.rm -rf node_modules yarn.lock package-lock.json
and re-installing packages.Description
Static assets ending in
.js
seem to be modified in adocusaurus build
.Reproducible demo
No response
Steps to reproduce
Create a new Docusaurus project.
Create a static asset containing some JavaScript.
Build and serve the project.
Open
localhost:3000/example.js
in your browser and observe that the content served by the browser does not look like the original file anymore, but like this.This does not happen when renaming the file to use a different extension, such as
.txt
.Expected behavior
I would expect Docusaurus not to modify the contents of static
.js
assets.Actual behavior
Docusaurus actually transformed the asset.
Your environment
uname -a
: MSYS_NT-10.0-19045 NB01508 3.4.10-2e2ef940.x86_64 2024-07-09 21:35 UTC x86_64 MsysSelf-service