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

Vite includes source files into the production bundle out of the box #17514

Closed
7 tasks done
vladmw5 opened this issue Jun 18, 2024 · 3 comments
Closed
7 tasks done

Vite includes source files into the production bundle out of the box #17514

vladmw5 opened this issue Jun 18, 2024 · 3 comments

Comments

@vladmw5
Copy link

vladmw5 commented Jun 18, 2024

Describe the bug

I have created a brand new react-vite project using yarn create vite . --template=react-ts

When I launched the dev server, I found that in the Network tab all my source files like main.tsx and App.tsx are included, which is obviously undesirable due to security reasons. Newly created files are also included as ts files.

What I expect is that ts files should not be included, only the final minified js script

Reproduction

https://github.com/vladmw5/react-vite-ts-test

Steps to reproduce

Run yarn dev

Visit the local server

Open devtools (F12)

Open the Network tab

Toggle All and See *.tsx and *.ts files being fetched

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 AMD Ryzen 7 5800H with Radeon Graphics
    Memory: 3.73 GB / 15.35 GB
  Binaries:
    Node: 20.13.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.5.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.9.0 - ~\AppData\Local\pnpm\pnpm.EXE
  Browsers:
    Edge: Chromium (126.0.2592.56)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @vitejs/plugin-react: ^4.2.1 => 4.3.1
    vite: ^5.2.0 => 5.3.1

Used Package Manager

yarn

Logs

No response

Validations

@bluwy
Copy link
Member

bluwy commented Jun 24, 2024

This is how Vite works fundamentally. In dev, the source files are served as is and transformed to JS. If you want to build them away, you need to build your project with vite build and preview it.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Jun 24, 2024
@vrxrg
Copy link

vrxrg commented Jun 24, 2024

Thank you! So you claim that if experience this behaviour in production, that signifies that I run my prod with 'dev bundle' instead of the one generated by vite build?

@bluwy
Copy link
Member

bluwy commented Jun 24, 2024

Yes, if you see that, you may be running the dev server and using that server as-is in prod, which will have many other issues. Not to be mistaken though with production sourcemaps, as they can display the file structure and original code in the sources tab (not the network tab).

@github-actions github-actions bot locked and limited conversation to collaborators Jul 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants