Bun / Bundle With External Dependencies
Bundle With External Dependencies
Bundle JavaScript with external dependencies specified.
bun build <path/to/entry.ts> --outfile <path/to/output.js> -e <react react-dom> bun build <path/to/entry.ts> --outfile <path/to/output.js> -e <react react-dom> #!/bin/bash
# Bundle With External Dependencies
bun build {{path/to/entry.ts}} --outfile {{path/to/output.js}} {{[-e|--external]}} {{react react-dom}} import subprocess
# Bundle With External Dependencies
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"bun",
"build",
"<path/to/entry.ts>",
"--outfile",
"<path/to/output.js>",
"-e",
"{{react",
"react-dom}}"
]
try:
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: bun not found. Please install it first.")
if __name__ == "__main__":
run_command() When To Use
When integrating third-party libraries that should not be bundled into the final artifact for smaller output sizes.
Pro Tip
Consider using a specific version range for external dependencies to avoid compatibility issues.
Terminal Output
Expected runtime feedback
Build started...
Bundling /path/to/entry.ts with external dependencies:
- react
- react-dom
Output file created at /path/to/output.js
Build completed successfully! Anatomy of Output
Understanding the result
Bundling dependencies: [react, react-dom] External Dependencies Shows which external libraries are being referenced.
Package not found: react-dom Dependency Status Indicates if any specified external package is missing.
Bundled successfully in 600 ms with external dependencies. Bundle Summary Completion time for the bundling process.
Troubleshooting
Common pitfalls
Error: Package react is not listed as a dependency
Solution: Add react to your project's dependency list.
Error: Unmet peer dependency: react-dom
Solution: Ensure the compatible version of react is installed.
Error: Unable to locate external dependency 'react'
Solution: Check repository URL or package installation.
Command Breakdown
What each part is doing
-
bun - Base Command
- The executable that performs this operation. Here it runs Bun before the shell applies any redirect operators.
-
<path/to/entry.ts> - path to entry.ts
- The value supplied for path to entry.ts.
-
<path/to/output.js> - path to output.js
- The value supplied for path to output.js.
-
-e - e| external
- The value supplied for e| external.
-
<react react-dom> - react react dom
- The value supplied for react react dom.
-
--outfile - Command Option
- Tool-specific option used by this command invocation.
-
-e - Command Option
- Tool-specific option used by this command invocation.
How To Run
Execution path
- Step 1
Run the command: bun build /path/to/entry.ts --outfile /path/to/output.js --external react react-dom
- Step 2
Check the output file at /path/to/output.js to verify the bundling was successful.
Alternative Approaches
Comparable commands in other tools
Alternative build tools tools for the same job.
automake --foreign Secon / Get Security Context Symlink Linux secon --link <path/to/symlink> Babel / Watch File For Changes And Transpile babel <path/to/input_file> --watch Dcg / Generate Code In Specific Directory dcg --directory <path/to/directory> Go / Run Go Link Tool go tool link <path/to/main.o>