Installations
npm install @putout/bundler
Developer Guide
Typescript
No
Module System
ESM
Min. Node Version
>=18
Node Version
20.11.1
NPM Version
10.5.0
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
putoutjs
Download Statistics
Total Downloads
7,109
Last Day
33
Last Week
365
Last Month
1,488
Last Year
6,971
GitHub Statistics
MIT License
2 Stars
18 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Jul 03, 2024
Package Meta Information
Latest Version
1.1.1
Package Id
@putout/bundler@1.1.1
Unpacked Size
16.25 kB
Size
5.41 kB
File Count
14
NPM Version
10.5.0
Node Version
20.11.1
Published on
Apr 09, 2024
Total Downloads
Cumulative downloads
Total Downloads
7,109
Last Day
371.4%
33
Compared to previous day
Last Week
-17.6%
365
Compared to previous week
Last Month
76.5%
1,488
Compared to previous month
Last Year
4,951.4%
6,971
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
16
Bundler

Install
npm i @putout/bundle
API
1import {bundle} from '@putout/bundler'; 2 3console.log(bundle(CWD, entry, filesystem));
Internals
Convert ESM to CommonJS
To Simplify things up all files converted to CommonJS first. Let's suppose none of them use top-level await to get things simpler.
Parse filenames
Traverse all files starting from entry
and get all filenames.
Bundle all files to object
Traverse filesystem and create object that contains filename and file content:
1const __filesystem = { 2 '/entry.js': () => { 3 const client = require('/client.js'); 4 console.log(client); 5 }, 6 '/client.js': (exports, require, module) => { 7 module.exports = 'hello'; 8 }, 9};
IIFE
Most likely we need IIFE so couple bundles can be loaded on page simultaneously.
Result Example
1const __modules = {}; 2const __filesystem = { 3 '/entry.js': () => { 4 const client = require('/client.js'); 5 console.log(client); 6 }, 7 '/client.js': (exports, require, module) => { 8 module.exports = 'hello'; 9 }, 10}; 11 12const require = (name) => { 13 const exports = {}; 14 const module = { 15 exports, 16 }; 17 18 if (__modules[name]) 19 return __modules[name]; 20 21 __filesystem[name](exports, require, module); 22 __modules[name] = module.exports; 23 24 return module.exports; 25}; 26 27require('/entry.js');
License
MIT

No vulnerabilities found.

No security vulnerabilities found.