File
Blob: src/pyodide/internal/pool/esbuild.config.mjs
| 1 | import { dirname, join } from 'node:path'; |
| 2 | import { existsSync } from 'node:fs'; |
| 3 | import { fileURLToPath } from 'url'; |
| 4 | |
| 5 | const pyodideRootDir = dirname( |
| 6 | dirname(dirname(fileURLToPath(import.meta.url))) |
| 7 | ); |
| 8 | |
| 9 | const pyodideVersion = '%PYODIDE_VERSION%'; |
| 10 | |
| 11 | let resolvePlugin = { |
| 12 | name: 'pyodide-internal', |
| 13 | setup(build) { |
| 14 | // Redirect all paths starting with "images/" to "./public/images/" |
| 15 | build.onResolve({ filter: /pyodide-internal:.*/ }, (args) => { |
| 16 | let rest = args.path.split(':')[1]; |
| 17 | let path; |
| 18 | if (rest.startsWith('generated')) { |
| 19 | path = join(pyodideRootDir, pyodideVersion, rest); |
| 20 | if (!existsSync(path)) { |
| 21 | if (existsSync(path + '.js')) { |
| 22 | path += '.js'; |
| 23 | } else { |
| 24 | path += '.mjs'; |
| 25 | } |
| 26 | } |
| 27 | } else { |
| 28 | path = join(pyodideRootDir, 'internal', rest); |
| 29 | if (!existsSync(path)) { |
| 30 | path += '.ts'; |
| 31 | } |
| 32 | } |
| 33 | return { path }; |
| 34 | }); |
| 35 | }, |
| 36 | }; |
| 37 | |
| 38 | export default { |
| 39 | plugins: [resolvePlugin], |
| 40 | logOverride: { |
| 41 | // Suppress warning about CommonJS 'module' variable in pyodide.asm.js (ES module context) |
| 42 | // The pyodide.asm.js file contains embedded libraries (like MiniLZ4) that use CommonJS |
| 43 | // style module.exports checks for compatibility. These are safe to ignore as they won't |
| 44 | // execute in our ES module context. |
| 45 | 'commonjs-variable-in-esm': 'silent', |
| 46 | }, |
| 47 | }; |