
Doh uses esbuild, a fast JavaScript bundler, for bundle sizes and loading times. The integration includes:
esbuild_doh_plugin.js)esbuild_processor.js)The ESBuild processor is configured through the esbuild_processor Pod:
Doh.Pod('esbuild_processor', {
esbuild_options: {
bundle: true,
outdir: DohPath('/dist/esm-bundles'),
format: 'esm',
splitting: true,
chunkNames: 'chunks/[name]-[hash]',
minify: true,
treeShaking: false,
keepNames: true,
preserveSymlinks: false,
target: 'esnext',
platform: 'browser',
mainFields: [
'browser',
'module',
'main'
],
logLevel: 'silent'
}
})
The primary options include:
| Option | Description |
|---|---|
bundle |
Combines all dependencies into a single file |
outdir |
Output directory for bundled files |
format |
Output format (esm, cjs, iife) |
splitting |
Enables code splitting for optimized chunks |
minify |
Reduces file size through minification |
treeShaking |
Removes unused code (disabled by default) |
target |
JavaScript target version |
platform |
Target platform (browser or node) |
mainFields |
Package entry point resolution order |
The custom Doh ESBuild plugin is configured via the esbuild_doh_plugin Pod:
Doh.Pod('esbuild_doh_plugin', {
esbuild_doh_plugin: {
deduplicate_packages: true,
fix_files: true,
replace_native_modules: true,
allow_external_resolution: true,
exclude_from_deduplication: [],
include_as_node_builtins: [
'http', 'https','worker_threads', 'term.js', 'pty.js'
],
empty_modules: []
}
})
The key options include:
| Option | Description |
|---|---|
deduplicate_packages |
Enables package deduplication |
fix_files |
Applies fixes for problematic files |
replace_native_modules |
Replaces Node.js builtin modules with browser-compatible versions |
allow_external_resolution |
Allows external module resolution |
exclude_from_deduplication |
Packages to exclude from deduplication |
include_as_node_builtins |
Additional modules to treat as Node.js builtins |
empty_modules |
Modules to replace with empty implementations |
Doh's esbuild integration includes package deduplication. This reduces bundle size by identifying and resolving duplicate package instances.
node_modules directoriesYou can control deduplication through the following settings:
deduplicate_packages: Enable/disable deduplication (default: true)exclude_from_deduplication: Array of package names to exclude from deduplication// Without deduplication
// - node_modules/package-a/node_modules/lodash (v4.17.20)
// - node_modules/package-b/node_modules/lodash (v4.17.21)
// - node_modules/lodash (v4.17.21)
// With deduplication
// All imports of lodash are redirected to the root instance (v4.17.21)
Doh works with the banal tool to visualize bundle sizes and dependencies.
dist/esm-bundles/build-meta.jsonbanal CLI command processes this file to create an interactive visualization:node doh banal
node doh banal open
The banal module is configured through its Doh module configuration:
Doh.Pod('banal', {
always_banal: false,
always_open_after_banal: false
});
Set always_banal to true to automatically generate visualizations after each build.
Doh's esbuild integration includes ECMAScript Modules (ESM) support:
// Generated at doh_js/manifests/browser_esm_manifest.json
{
"imports": {
"package-name": "/dist/esm-bundles/package-name.js",
// other mappings...
}
}
For browser compatibility, Doh uses the esbuild-plugins-node-modules-polyfill plugin to provide browser-compatible implementations of Node.js built-in modules.
The following Node.js builtins are polyfilled by default:
http and https for network requestsworker_threads for multithreadinginclude_as_node_builtinsTo use esbuild in your Doh project:
Doh.Install('esbuild', [
'npm:esbuild',
'npm:esbuild-plugins-node-modules-polyfill'
]);
Doh.Pod('my_project', {
esbuild_processor: {
// Custom esbuild options...
},
esbuild_doh_plugin: {
// Custom plugin options...
}
});
node doh esbuild
You can configure certain modules to be treated as external (not bundled):
Doh.Pod('esbuild_processor', {
esbuild_options: {
external: [
'large-package',
'problematic-package'
]
}
});
The esbuild_doh_plugin includes hooks for custom file transformations:
toForwardSlashThe plugin includes import path resolution:
mainFieldsDuplicate packages in bundle:
exclude_from_deduplicationMissing Node.js API in browser:
include_as_node_builtinsLarge bundle sizes:
treeShaking: true in esbuild optionsbanal to identify large dependenciesThe esbuild plugin includes detailed logging:
logLevel: 'debug' in esbuild options for verbose outputFor additional help with esbuild integration: