fib-rollup

raw JSON →
0.4.0 verified Mon Apr 27 auth: no javascript

A wrapper for running Rollup inside fibjs, a JavaScript runtime optimized for async I/O with coroutines. Version 0.4.0 allows using Rollup's JavaScript API with top-level await in fibjs's coroutine context. It provides a patched virtual machine (vbox) to emulate Node.js 'module' and other globals, enabling many Rollup plugins to run despite fibjs lacking full Node.js compatibility. Key differentiators: integrates Rollup's ES module bundling with fibjs's fiber-based concurrency; includes an internal 'rollup-plugin-fibjs-resolve' plugin as a fibjs-compatible alternative to 'rollup-plugin-node-resolve'. Limitations: not all Rollup plugins work, and CLI support is planned but not yet implemented.

error Error: Cannot find module 'rollup-plugin-node-resolve'
cause The plugin is not compatible with fibjs's module system.
fix
Use 'rollup-plugin-fibjs-resolve' (built-in) instead.
error TypeError: module is not a function
cause fibjs lacks the Node.js 'module' module.
fix
Ensure your script runs inside the vbox by using 'vbox.require' or the default rollup export.
error SyntaxError: await is only valid in async function
cause fibjs version <0.26.1 does not support top-level await.
fix
Wrap your code in an async function or upgrade fibjs.
gotcha Not all Rollup plugins are compatible with fibjs due to missing Node.js APIs.
fix Use only plugins known to work (e.g., rollup-plugin-commonjs) or test with fibjs's vbox. See plugin compatibility list in the docs.
gotcha fib-rollup uses a custom module resolution; some plugin imports may fail.
fix If a plugin fails, try using the provided vbox.getCustomizedVBox to patch missing modules.
gotcha Top-level await is only supported in fibjs >=0.26.1.
fix Upgrade fibjs to version >=0.26.1 or wrap code in an async function.
gotcha CLI mode is not implemented; only JavaScript API is available.
fix Use the programmatic API as shown in the quickstart.
npm install fib-rollup
yarn add fib-rollup
pnpm add fib-rollup

Demonstrates using fib-rollup to bundle a JavaScript file with the fibjs-resolve plugin, generating CommonJS output.

const path = require('path');
const { default: rollup, plugins } = require('fib-rollup');

async function build() {
    const bundle = await rollup.rollup({
        input: './src/index.js',
        plugins: [
            plugins['rollup-plugin-fibjs-resolve']()
        ]
    }).catch(e => console.error(e));

    if (bundle) {
        const { code } = await bundle.generate({ format: 'cjs' }).catch(e => console.error(e));
        console.log(code);
    }
}

build();