{"id":13686713,"url":"https://github.com/fibjs/fib-rollup","last_synced_at":"2025-06-12T12:13:30.290Z","repository":{"id":57235126,"uuid":"139562558","full_name":"fibjs/fib-rollup","owner":"fibjs","description":"fibjs wrapper for rollup","archived":false,"fork":false,"pushed_at":"2020-06-25T21:19:19.000Z","size":110,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-04T18:49:55.330Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fibjs.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-03T09:48:54.000Z","updated_at":"2020-06-25T21:19:21.000Z","dependencies_parsed_at":"2022-08-23T16:30:25.731Z","dependency_job_id":null,"html_url":"https://github.com/fibjs/fib-rollup","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/fibjs/fib-rollup","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibjs%2Ffib-rollup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibjs%2Ffib-rollup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibjs%2Ffib-rollup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibjs%2Ffib-rollup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fibjs","download_url":"https://codeload.github.com/fibjs/fib-rollup/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fibjs%2Ffib-rollup/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259462578,"owners_count":22861514,"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-02T15:00:38.373Z","updated_at":"2025-06-12T12:13:30.268Z","avatar_url":"https://github.com/fibjs.png","language":"TypeScript","funding_links":[],"categories":["Packages"],"sub_categories":["Packager/Transformer"],"readme":"# fib-rollup\n\n[![NPM version](https://img.shields.io/npm/v/fib-rollup.svg)](https://www.npmjs.org/package/fib-rollup)\n[![Build Status](https://travis-ci.org/fibjs/fib-rollup.svg)](https://travis-ci.org/fibjs/fib-rollup)\n[![Build status](https://ci.appveyor.com/api/projects/status/48822k7s2w38nh9p?svg=true)](https://ci.appveyor.com/project/richardo2016/fib-rollup)\n\nfibjs wrapper for rollup\n\n## Pre-requisite\n\n* fibjs `\u003e= 0.26.1`/ fibos `\u003e= 0.26.x`\n\nIt's recommended to use top-level `await` in fib-rollup's build script, just like case in [demo/] directory.\n\n* rollup knowledge\n\nBenefited by rollup's distinctive and predictive design, fibjs can run [rollup] perferctly with internal `vbox` Sandbox. [rollup] defined itself as `Next-generation ES module bundler`, and was written with typescript which can run in browser, nodejs and any other javascript context.\n\nJust get javascript API document in [rollupjs.org] later, before that, there're some issues you should notice. \n\nfibjs doesn't support all plugins of rollup(including those popular plugins such as [rollup-plugin-node-resolve]) because they use some nodejs APIs that fibjs haven't been compatible with yet.\n\nYou can alway run rollup, and write your own plugin, just like `fib-rollup`'s internal plugin \"rollup-plugin-fibjs-resolve\".\n\nWe also provide some [API](#API) to run existed rollup-plugin-\\* packages. See details about `vbox` and `getCustomizedVBox` in [API](#API) Section.\n\n## Usage\n\n```\nnpm i -D fib-rollup\n```\n\n### Via Javascript API\n\nsample build config\n\n```javascript\nconst { default: rollup, plugins } = require('fib-rollup')\n\nconst commonjs = require('@rollup/plugin-commonjs');\n\n// yes, just use top-level await!\n// get rollup instance `bundle`\nconst bundle = await rollup.rollup({\n    input: path.resolve(__dirname, './index.js'),\n    external: ['coroutine'],\n    plugins: [\n        plugins['rollup-plugin-fibjs-resolve'](),\n        commonjs()\n    ]\n}).catch(e =\u003e console.error(e));\n\n// generate code and map by `bundle.generate`\nconst { code, map } = await bundle.generate({\n    format: 'cjs'\n}).catch(e =\u003e console.error(e));\n\n// write bundled result with `bundle.write`\nawait bundle.write({\n    file: path.resolve(__dirname, './dist/bundle.js'),\n    format: 'cjs'\n}).catch(e =\u003e console.error(e));\n```\n\nview more demos in [demo/]\n\n### CLI\n\nwould be supported in the future.\n\n## APIs\n\n* `utils.vbox.getCustomizedVBox (myModules: any, myFallback: Function = recommendedVBoxModuleFallback)`\n\nget your own vbox by this API, vbox has some patched global module(such as `module`, `util`), but sometimes you need to another version patched global modules.\n\nVirtual box, it's based on fibjs's [vm.Sandbox], see detail in [src/utils/vbox.ts]. It provided some customzied global modules to make plugins running.\n\nSome of rollup-plugins can be run directly in raw fibjs's default global context, but some others must be hacked(or rewritten with fibjs). See details in [Plugins Test Result](#Plugins Test Result) below\n\nFor example, in fibjs there's no `module` module, which in nodejs is internal module and used to load nodejs' module. More and more npm packages use API in `module` module of nodejs, rollup did so. So I made one patched `module` module in default virtual box, and `vbox.require('rollup', __dirname)` to make rollup running. some of rollup's plugin can be run by this vbox.\n\ndefault patched modules is `recommendedVBoxModules`, see details in [src/utils/vbox.ts].\n\n* `utils.vbox.recommendedVBoxModules`\n\nsee details in [src/utils/vbox.ts]\n\n* `utils.vbox.recommendedVBoxModuleFallback`\n\nsee details in [src/utils/vbox.ts]\n\n## Internal Plugins\n\n**rollup-plugin-fibjs-resolve**\n---\n\n[rollup-plugin-node-resolve]'s fibjs version.\n\n[rollup-plugin-node-resolve] depends on nodejs's `module` module API heavily, it's hard, or say, impossible to provide one compatible `module` module to simulate [load-mechanism in nodejs] and make [rollup-plugin-node-resolve] running.\n\nfibjs's load-mechanism is based on [vm.Sandbox], which distinguished from `module` module in nodejs. I have to write the plugin with same API with [rollup-plugin-node-resolve], but only for fibjs.\n\n**type**: `fibjsResolve(options: RollupPluginFibjsResolveOptions = {})`\n\n```javascript\nconst path = require('path');\nconst { default: rollup, plugins } = require('../../')\n\nconst commonjs = require('@rollup/plugin-commonjs');\n\nconst bundle = await rollup.rollup({\n    input: path.resolve(__dirname, './index.js'),\n    external: ['coroutine'],\n    plugins: [\n        plugins['rollup-plugin-fibjs-resolve'](),\n        // use it with @rollup/plugin-commonjs\n        commonjs()\n    ]\n}).catch(e =\u003e console.error(e));\n```\n\n**rollup-plugin-uglify-js**\n---\n\n`uglify-js` wrapper for rollup on fibjs.\n\n```javascript\nconst path = require('path');\nconst { default: rollup, plugins } = require('../../')\n\nconst buble = require('@rollup/plugin-buble')\nconst commonjs = require('@rollup/plugin-commonjs');\n\nconst bundle = await rollup.rollup({\n    input: path.resolve(__dirname, './index.ts'),\n    external: ['coroutine'],\n    plugins: [\n        plugins['rollup-plugin-fibjs-resolve'](),\n        // transpile es201X feature such as template string\n        buble(),\n        commonjs(),\n        plugins['rollup-plugin-uglify-js']()\n    ]\n}).catch(e =\u003e console.error(e));\n```\n\n**rollup-plugin-uglify-es**\n---\n\n**Started from 0.4.0**\n\n`uglify-es` wrapper for rollup on fibjs.\n\n```javascript\nconst path = require('path');\nconst { default: rollup, plugins } = require('../../')\n\nconst commonjs = require('@rollup/plugin-commonjs');\n\nconst bundle = await rollup.rollup({\n    input: path.resolve(__dirname, './index.js'),\n    external: ['coroutine'],\n    plugins: [\n        plugins['rollup-plugin-fibjs-resolve'](),\n        commonjs(),\n        plugins['rollup-plugin-uglify-es']()\n    ]\n}).catch(e =\u003e console.error(e));\n```\n\n**rollup-plugin-babel-standalone(Beta)**\n---\n\nuse `babel-standalone` to transform javascript\n\n```javascript\nconst path = require('path');\nconst { default: rollup, plugins } = require('../../')\n\nconst commonjs = require('@rollup/plugin-commonjs');\n\nconst bundle = await rollup.rollup({\n    input: path.resolve(__dirname, './index.ts'),\n    external: ['coroutine'],\n    plugins: [\n        plugins['rollup-plugin-fibjs-resolve'](),\n        // transpile es201X feature such as template string\n        plugins['rollup-plugin-babel-standalone']({\n            // ...transform options, you can also set it in `$CWD/.babelrc` or `path.dirname(input)/.babelrc`\n            presets: [\n                [\"es2015\", { \"modules\": false }],\n                // ...\n            ]\n        }),\n        commonjs(),\n        plugins['rollup-plugin-uglify-js']()\n    ]\n}).catch(e =\u003e console.error(e));\n```\n\n## Document\n\n[rollupjs.org]\n\n## Feature\n\n- [x] pure javascript bundle\n    - [ ] fibos\n- [x] server-side bundle\n- [x] frontend javacript bundle\n    - [ ] react\n    - [ ] angular\n    - [ ] jquery\n    - [ ] cheerio\n\n## Plugins Test Result\n\n| Plugin Name | required version | Is Valid? | Comment |\n| --- | --- | --- | --- |\n| [@rollup/plugin-buble] | `v0.2.0`  | ✔️ | valid but it's not recommended to use with `http.Server`, it would lead to memory leak sometimes. |\n| [@rollup/plugin-commonjs] | `v0.2.0`  | ✔️ | |\n| [rollup-plugin-pug] | `v0.2.0`  | ✔️ | |\n| [@rollup/plugin-json] | `v0.2.0`  | ✔️ | |\n| [rollup-plugin-graph] | -  | ❌ | |\n| [@rollup/plugin-typescript] | `v0.2.2`  | ✔️ | **pass `extensions: ['.ts']`**; \u003cbr\u003e rollup compile typescript file(entry or module) automatically. |\n| [rollup-plugin-virtual] | `v0.2.0`  | ✔️ | |\n| [rollup-plugin-uglify] | -  | ❌  | |\n| [rollup-plugin-terser] | -  | ❌  | |\n| [@rollup/plugin-alias] | `v0.2.0`  | ✔️  | |\n\n\u003c!-- ❌ --\u003e\n\n## Development\n\nfork this repo, run commands\n\n```bash\nnpm i -D\n\n# build\nnpm run build\n\n# run test\nnpm run ci\n```\n\n## License\n\n[GPL-3.0](https://opensource.org/licenses/GPL-3.0)\n\nCopyright (c) 2018-present, Richard\n\n[demo/]:demo/\n[rollup]:https://github.com/rollup/rollup\n[rollupjs.org]:https://rollupjs.org/\n[rollup-plugin-node-resolve]:https://www.npmjs.com/package/rollup-plugin-node-resolve\n[vm.Sandbox]:https://github.com/fibjs/fibjs/blob/master/idl/zh-cn/SandBox.idl\n[src/utils/vbox.ts]:src/utils/vbox.ts\n[load-mechanism in nodejs]:https://github.com/nodejs/node/blob/master/lib/module.js\n\n[@rollup/plugin-buble]:https://www.npmjs.com/package/@rollup/plugin-buble\n[@rollup/plugin-commonjs]:https://www.npmjs.com/package/@rollup/plugin-commonjs\n[rollup-plugin-pug]:https://www.npmjs.com/package/rollup-plugin-pug\n[@rollup/plugin-json]:https://www.npmjs.com/package/@rollup/plugin-json\n[rollup-plugin-vue]:https://www.npmjs.com/package/rollup-plugin-vue\n[@rollup/plugin-typescript]:https://www.npmjs.com/package/@rollup/plugin-typescript\n[rollup-plugin-graph]:https://www.npmjs.com/package/rollup-plugin-graph\n[rollup-plugin-virtual]:https://www.npmjs.com/package/rollup-plugin-virtual\n[rollup-plugin-uglify]:https://www.npmjs.com/package/rollup-plugin-uglify\n[rollup-plugin-terser]:https://www.npmjs.com/package/rollup-plugin-terser\n[@rollup/plugin-alias]:https://www.npmjs.com/package/@rollup/plugin-alias\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffibjs%2Ffib-rollup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffibjs%2Ffib-rollup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffibjs%2Ffib-rollup/lists"}