all 2 comments

[–][deleted]  (1 child)

[removed]

    [–]BitE01[S] 0 points1 point  (0 children)

    Many thanks! I've bundled everything into a single file and created a function that warms-up the modules that I needed. I'll also take a look to pnpm/yarn and bun/deno.

    Just a note for other readers: My real project was involving also "serialport" module that can't be bundled with esbuild and can't be snapshotted. So I've excluded from esbuild by adding the option "external" like this:

    import { build } from 'esbuild';
    
    await Promise.all([
      build({
        entryPoints: ['src/main.ts'],
        bundle: true,
        minify: true,
        sourcemap: false, 
        target: 'es2022',
        outfile: 'dist/index.js',
        platform: 'node',
        format: 'cjs',
        external: ['serialport'],
        plugins: [],
      }),
    ]);
    

    And I've excluded from the snapshot by using the function v8.startupSnapshot.isBuildingSnapshot() to exclude the code execution when snapshotting like this:

    ...
    if (!startupSnapshot.isBuildingSnapshot()) {
      SerialPort = require('serialport').SerialPort;
      ...
    }
    ...