{"id":13547731,"url":"https://github.com/WebReflection/asbundle","last_synced_at":"2025-04-02T20:30:41.149Z","repository":{"id":57184588,"uuid":"107398379","full_name":"WebReflection/asbundle","owner":"WebReflection","description":"A minimalistic JS bundler","archived":false,"fork":false,"pushed_at":"2020-09-10T06:25:35.000Z","size":198,"stargazers_count":79,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T14:11:09.184Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WebReflection.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-18T11:25:10.000Z","updated_at":"2024-10-30T16:24:20.000Z","dependencies_parsed_at":"2022-09-14T09:01:01.584Z","dependency_job_id":null,"html_url":"https://github.com/WebReflection/asbundle","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fasbundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fasbundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fasbundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WebReflection%2Fasbundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WebReflection","download_url":"https://codeload.github.com/WebReflection/asbundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246887802,"owners_count":20850144,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T12:01:00.257Z","updated_at":"2025-04-02T20:30:40.704Z","avatar_url":"https://github.com/WebReflection.png","language":"JavaScript","readme":"# asbundle\n\n[![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000\u0026style=flat)](https://github.com/WebReflection/donate) [![License: ISC](https://img.shields.io/badge/License-ISC-yellow.svg)](https://opensource.org/licenses/ISC) [![Build Status](https://travis-ci.org/WebReflection/asbundle.svg?branch=master)](https://travis-ci.org/WebReflection/asbundle) [![Greenkeeper badge](https://badges.greenkeeper.io/WebReflection/asbundle.svg)](https://greenkeeper.io/)\n\nA minimalistic CommonJS bundler.\n\n- - -\n\nThis module is a perfect [ascjs](https://github.com/WebReflection/ascjs) companion to create CommonJS bundles.\n\nPassing a single ESM/CJS source file as path name, it will produce a lightweight, optimized, and minifier friendly bundle,\nto consume right away without needing global `require` or runtime discovered CommonJS dependencies.\n\n### Goals\n  * be as simple as possible, but not simpler\n  * make creation of small modules written in ESM a no brainer\n  * enable `.js` files as ESM everywhere, following a simple folder convention\n  * produce files compatible with most common bundlers and tools (Babel, Webpack, UglifyJS, etc)\n\n**Example** of a basic module based on _ascjs_ and _asbundle_.\n\n\u003cimg src=\"https://github.com/WebReflection/asbundle/raw/master/module-structure.png\" width=\"307\"\u003e\n\n### Non-Goals\n  * replace Babel, Webpack, Rollup, or any other tool. Let them do complicated things when needed\n  * transpile anything else than ESM import/export declarations\n\n## How to\n\nYou can use _asbundle_ as binary utility or as module.\n\n```sh\nnpm install -g asbundle\n\n# to see what you can do\nasbundle --help\n\n```\n\nAs executable, you can use _asbundle_ to output, or save, a bundle entry point.\n```sh\nasbundle source-file.js           # writes bundle contents to STDOUT\nasbundle source-file.js bundle.js # outputs to bundle.js\n```\n\nAs module, you can require it and use it to obtain a bundle string.\n```js\nconst asbundle = require('asbundle');\n\nasbundle(sourceFileName);\n```\n\n### Features\n\n  * extremely lightweight, based on [babylon](https://github.com/babel/babylon) for performance and reliability\n  * it uses _ascjs_ to automatically transform, when needed, ES2015+ modules into CommonJS code\n  * understands both relative files and installed packages too (based on `require.resolve(...)`)\n  * reproduces a modern and minimalistic CommonJS environments ideal for browsers\n  * compatible with [Babel](http://babeljs.io) `__esModule` and `.default` convention\n\n### Constrains\n\n  * same constrains of [ascjs](https://github.com/WebReflection/ascjs#constrains)\n  * Node core modules are not brought to the bundle, if a module cannot be resolved as file name it throws\n\n### Example\nThis module can transform `main.js` entry file via `asbundle main.js out.js`:\n```js\n// main.js\nimport func, {a, b} from './module.js';\nconst val = 123;\nexport default function test() {\n  console.log('asbundle');\n};\nexport {func, val};\n\n// module.js\nexport const a = 1, b = 2;\nexport default function () {\n  console.log('module');\n};\n```\ninto the following bundle:\n```js\n// out.js =\u003e 266 bytes minified \u0026 gzipped\n(function (cache, modules) {\n  function require(i) { return cache[i] || get(i); }\n  function get(i) {\n    var exports = {}, module = {exports: exports};\n    modules[i].call(exports, window, require, module, exports);\n    return (cache[i] = module.exports);\n  }\n  var main = require(0);\n  return main.__esModule ? main.default : main;\n}([],[function (global, require, module, exports) {\n// main.js\n'use strict';\nconst func = (m =\u003e m.__esModule ? m.default : m)(require(1));\nconst {a, b} = require(1);\nconst val = 123;\nfunction test() {\n  console.log('asbundle');\n}\nObject.defineProperty(exports, '__esModule', {value: true}).default = test;\nexports.func = func;\nexports.val = val;\n},function (global, require, module, exports) {\n// module.js\n'use strict';\nconst a = 1, b = 2;\nexports.a = a;\nexports.b = b;\nObject.defineProperty(exports, '__esModule', {value: true}).default = function () {\n  console.log('module');\n};\n}]));\n```\n\nThe main module is returned and executed as default entry so it becomes easy to publish as global variable for Web purposes too.\n\nAdd a `const myModule = ` prefix to the bundled code and use it right away.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWebReflection%2Fasbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FWebReflection%2Fasbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWebReflection%2Fasbundle/lists"}