-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] fix ty playground initialization and vite optimization issues #21471
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
base: main
Are you sure you want to change the base?
Conversation
playground/ty/vite.config.ts
Outdated
| targets: [ | ||
| { | ||
| src: [join(pyodideDir, "*"), ...PYODIDE_EXCLUDE], | ||
| src: [join(pyodideDir, "*").replace(/\\/g, "/"), ...PYODIDE_EXCLUDE], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes little sense to me, given that path.join uses the platform-specific path separator. Which path contains the / where windows expects a \?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a statement about this limitation here:
If you are using Windows, make sure to use normalizePath after doing path.resolve or else. \ is a escape charactor in tinyglobby and you should use /.
According to this description, using normalizePath is a more robust approach, so I changed it to use that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, this is a glob and not a path.
I suggest then to call normalizePath(pyodideDir) (or normalize before assigning to pyodideDir) to scope the normalize exactly to where it's necessary.
| export default defineConfig({ | ||
| plugins: [react(), tailwindcss(), viteStaticCopyPyodide()], | ||
| optimizeDeps: { exclude: ["pyodide"] }, | ||
| optimizeDeps: { exclude: ["pyodide", "ty_wasm"] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use vite for the production builds. Can you verify that the vite build reported sizes are the same before and after your changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Build results on Ubuntu (@ WSL2):
main:
❯ dust ty/dist
24K ┌── Astral.png │█ │ 0%
20K │ ┌── pyodide.mjs │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
20K │ ├── solidity-CVYD1GVc.js │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
24K │ ├── tsMode-De4b9PNo.js │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
36K │ ├── cssMode-cNRTyZYV.js │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
36K │ ├── htmlMode-BieFvPPN.js │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
44K │ ├── ffi.d.ts │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
44K │ ├── jsonMode-B6VJCXeF.js │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
68K │ ├── pyodide.d.ts │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
84K │ ├── pyodide.js.map │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
84K │ ├── pyodide.mjs.map │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
92K │ ├── codicon-B_Z2XQ3P.ttf │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
112K │ ├── pyodide-lock.json │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
144K │ ├── editor-BhPcksyq.css │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
396K │ ├── index-BeD-OYFt.js │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 1%
1.0M │ ├── pyodide.asm.js │███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 4%
2.3M │ ├── python_stdlib.zip │█████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 8%
3.5M │ ├── editor.main-ClkAP-6o.js │████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 12%
8.2M │ ├── pyodide.asm.wasm │██████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 29%
11M │ ├── ty_wasm_bg-Bd9OBY4A.wasm│██████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 41%
28M ├─┴ assets │█████████████████████████████████████████████████████████████ │ 100%
28M ┌─┴ dist │█████████████████████████████████████████████████████████████ │ 100%❯ dust ty/dist
24K ┌── Astral.png │█ │ 0%
20K │ ┌── pyodide.mjs │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
20K │ ├── solidity-CVYD1GVc.js │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
24K │ ├── tsMode-Bzlyl_WG.js │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
36K │ ├── cssMode-BItooz1B.js │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
36K │ ├── htmlMode-XS2Ok6yb.js │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
44K │ ├── ffi.d.ts │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
44K │ ├── jsonMode-Bw4_M6_V.js │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
68K │ ├── pyodide.d.ts │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
84K │ ├── pyodide.js.map │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
84K │ ├── pyodide.mjs.map │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
92K │ ├── codicon-B_Z2XQ3P.ttf │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
112K │ ├── pyodide-lock.json │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
144K │ ├── editor-BhPcksyq.css │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 0%
396K │ ├── index-B_J2zKKC.js │█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 1%
1.0M │ ├── pyodide.asm.js │███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 4%
2.3M │ ├── python_stdlib.zip │█████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 8%
3.5M │ ├── editor.main-CF30gs3G.js │████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 12%
8.2M │ ├── pyodide.asm.wasm │██████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 29%
11M │ ├── ty_wasm_bg-C8Ofe_-K.wasm│██████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ │ 41%
28M ├─┴ assets │█████████████████████████████████████████████████████████████ │ 100%
28M ┌─┴ dist │█████████████████████████████████████████████████████████████ │ 100%This result is consistent with what the vite document states.
47ad620 to
6d632b1
Compare
Summary
I tried to build the ty playground on my Windows machine and run it locally, but it didn't work. I got the following error:
Also, nothing is displayed when I access localhost:5173. The following error appears in the browser console:
This PR fixes the above issues.
First, for the first issue with vite-plugin-static-copy, I addressed it by changing backslashes
\to slashes/in the path name. This is a common Windows-specific path handling issue.For the other issue, I changed the
ty_wasmpackage import from a relative path to a package name, and excludedty_wasmfromoptimizeDepsin vite.config.js.To be honest, I'm not familiar with vite, so I'm not sure why this worked, but I tried the workaround described here:
vitejs/vite#8427
The above changes are for development purposes only and should not affect the content actually delivered.
Test Plan
N/A