Closed philips closed 5 months ago
Hrm, two hurdles looking into this more:
Some breadcrumbs from gemini and research:
While esbuild doesn't directly support Pyodide, here's a workaround approach to package your project:
1. Structure Your Project:
project_root/
├── package.json
├── pyodide-lock.json
├── pyodide/
│ ├── pyodide.asm.js
│ ├── pyodide.asm.wasm
│ ├── pyodide.js
│ ├── pyodide.mjs
│ └── python_stdlib.zip
├── src/ (JavaScript source files)
│ └── ...
└── build/ (Destination for bundled files)
2. Install esbuild:
npm install --save-dev esbuild
3. Create a Build Script:
build.js
) to configure the bundling process:import { build } from 'esbuild';
build({
entryPoints: ['src/index.js'], // Adjust based on your entry file
bundle: true,
outfile: 'build/bundle.js',
format: 'esm',
define: {
// Define any necessary Pyodide-related globals
PYODIDE: 'pyodide', // Example if you're using Pyodide globally
},
external: [
'pyodide/pyodide.asm.js',
'pyodide/pyodide.asm.wasm',
'pyodide/pyodide.js',
'pyodide/pyodide.mjs',
'pyodide/python_stdlib.zip',
],
});
4. Run the Build:
node build.js
5. Serve Bundled Files:
build
folder, ensuring the Pyodide files are accessible from the same relative path:bundle.js
pyodide/
└── ... (Pyodide files)
Key Considerations:
Esbuild currently doesn't have direct support for integrating Python wheels, including Pyodide wheels. Wheels are designed for installation within a Python environment, not directly in a JavaScript bundler like esbuild.
Here are some alternative approaches to consider:
file-loader
or a custom loader suitable for Pyodide wheels in Webpack.Remember:
It's best to choose the approach that aligns best with your project's needs and your comfort level with different tools.
This is probably not worthwhile now. Closing
One idea to avoid porting all of @jya-dev 's work on https://github.com/jya-dev/supernote-tool is to use pyodide to pull the python libraries into WASM. It seems most of the dependencies work out of the box: https://github.com/philips/obsidian-plugin-supernote/compare/main...pyodide