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

Do not transform static JS assets #10460

Open
6 of 7 tasks
erke-soptim opened this issue Aug 30, 2024 · 7 comments
Open
6 of 7 tasks

Do not transform static JS assets #10460

erke-soptim opened this issue Aug 30, 2024 · 7 comments
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: bundler

Comments

@erke-soptim
Copy link

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

Static assets ending in .js seem to be modified in a docusaurus build.

Reproducible demo

No response

Steps to reproduce

Create a new Docusaurus project.

npx create-docusaurus@latest my-website classic --typescript
cd my-website

Create a static asset containing some JavaScript.

echo "let a = 1; let b = 2;" > ./static/example.js

Build and serve the project.

npm run build
npm run serve

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.

let a=1,b=2;

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

  • Docusaurus version used: 3.5.2
  • Result of uname -a: MSYS_NT-10.0-19045 NB01508 3.4.10-2e2ef940.x86_64 2024-07-09 21:35 UTC x86_64 Msys
  • Environment: Chrome Version 128.0.6613.113 (Official Build) (64-bit)

Self-service

  • I'd be willing to fix this bug myself.
@erke-soptim erke-soptim added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Aug 30, 2024
@OzakIOne
Copy link
Contributor

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 ?

@OzakIOne OzakIOne removed bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Aug 30, 2024
@Josh-Cena
Copy link
Collaborator

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.

@Josh-Cena Josh-Cena added the bug An error in the Docusaurus core causing instability or issues with its execution label Aug 30, 2024
@Josh-Cena
Copy link
Collaborator

Ah, #10334 should be similar. Perhaps they are the same issue.

@erke-soptim
Copy link
Author

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.

@hrumhurum
Copy link

hrumhurum commented Sep 2, 2024

Perhaps related to #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.

@allenscha
Copy link

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.

@thomasmattheussen
Copy link

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 #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: bundler
Projects
None yet
Development

No branches or pull requests

6 participants