node.jsgypchakracore

How can I build node.js without some internal modules?


I want to build a specific nodejs as a static library without some internal module like child_process dns etc.

Is there a configurable way to go about this?


Solution

  • Remove the modules you don't want from node.gyp, remove the .js files from the lib folder, remove them from the builtinLibs array in lib/internal/module.js then build it.

    {
      'variables': {
        'v8_use_snapshot%': 'false',
        'v8_trace_maps%': 0,
        'node_use_dtrace%': 'false',
        'node_use_lttng%': 'false',
        'node_use_etw%': 'false',
        'node_use_perfctr%': 'false',
        'node_no_browser_globals%': 'false',
        'node_use_v8_platform%': 'true',
        'node_use_bundled_v8%': 'true',
        'node_shared%': 'false',
        'force_dynamic_crt%': 0,
        'node_module_version%': '',
        'node_shared_zlib%': 'false',
        'node_shared_http_parser%': 'false',
        'node_shared_cares%': 'false',
        'node_shared_libuv%': 'false',
        'node_use_openssl%': 'true',
        'node_shared_openssl%': 'false',
        'node_v8_options%': '',
        'node_enable_v8_vtunejit%': 'false',
        'node_core_target_name%': 'node',
        'library_files': [
          'lib/internal/bootstrap_node.js',
          'lib/async_hooks.js',
          'lib/assert.js',
          'lib/buffer.js',
          'lib/child_process.js', //Remove this line
          'lib/console.js',
          'lib/constants.js',
          'lib/crypto.js',
          'lib/cluster.js',
          'lib/dgram.js',
          'lib/dns.js', //Remove this line too
    [...]
    

    Be aware that these modules are used in tests and benchmarks, and for example with child_proccess, in lib/internal/v8_prof_polyfill.js and lib/internal/cluster/master.js