[ty] fix ty playground initialization and vite optimization issues (#21471)

Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
Shunsuke Shibayama 2025-11-25 16:42:56 +09:00 committed by GitHub
parent adf095e889
commit dd15656deb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -501,7 +501,7 @@ export interface InitializedPlayground {
// Run once during startup. Initializes monaco, loads the wasm file, and restores the previous editor state. // Run once during startup. Initializes monaco, loads the wasm file, and restores the previous editor state.
async function startPlayground(): Promise<InitializedPlayground> { async function startPlayground(): Promise<InitializedPlayground> {
const ty = await import("../ty_wasm"); const ty = await import("ty_wasm");
await ty.default(); await ty.default();
const version = ty.version(); const version = ty.version();
const monaco = await loader.init(); const monaco = await loader.init();

View File

@ -3,6 +3,7 @@ import tailwindcss from "@tailwindcss/vite";
import react from "@vitejs/plugin-react-swc"; import react from "@vitejs/plugin-react-swc";
import { dirname, join } from "path"; import { dirname, join } from "path";
import { fileURLToPath } from "url"; import { fileURLToPath } from "url";
import { normalizePath } from "vite";
import { viteStaticCopy } from "vite-plugin-static-copy"; import { viteStaticCopy } from "vite-plugin-static-copy";
const PYODIDE_EXCLUDE = [ const PYODIDE_EXCLUDE = [
@ -15,15 +16,17 @@ const PYODIDE_EXCLUDE = [
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [react(), tailwindcss(), viteStaticCopyPyodide()], plugins: [react(), tailwindcss(), viteStaticCopyPyodide()],
optimizeDeps: { exclude: ["pyodide"] }, optimizeDeps: { exclude: ["pyodide", "ty_wasm"] },
}); });
export function viteStaticCopyPyodide() { export function viteStaticCopyPyodide() {
const pyodideDir = dirname(fileURLToPath(import.meta.resolve("pyodide"))); const pyodideDir = normalizePath(
join(dirname(fileURLToPath(import.meta.resolve("pyodide"))), "*"),
);
return viteStaticCopy({ return viteStaticCopy({
targets: [ targets: [
{ {
src: [join(pyodideDir, "*"), ...PYODIDE_EXCLUDE], src: [pyodideDir, ...PYODIDE_EXCLUDE],
dest: "assets", dest: "assets",
}, },
], ],