Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

fib-rollup

fibjs25GPL-3.00.4.0TypeScript support: included

rollup wrapper of fibjs

fibjs, rollup

readme

fib-rollup

NPM version Build Status Build status

fibjs wrapper for rollup

Pre-requisite

  • fibjs >= 0.26.1/ fibos >= 0.26.x

It's recommended to use top-level await in fib-rollup's build script, just like case in demo/ directory.

  • rollup knowledge

Benefited 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.

Just get javascript API document in rollupjs.org later, before that, there're some issues you should notice.

fibjs 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.

You can alway run rollup, and write your own plugin, just like fib-rollup's internal plugin "rollup-plugin-fibjs-resolve".

We also provide some API to run existed rollup-plugin-* packages. See details about vbox and getCustomizedVBox in API Section.

Usage

npm i -D fib-rollup

Via Javascript API

sample build config

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

const commonjs = require('rollup-plugin-commonjs');

// yes, just use top-level await!
// get rollup instance `bundle`
const bundle = await rollup.rollup({
    input: path.resolve(__dirname, './index.js'),
    external: ['coroutine'],
    plugins: [
        plugins['rollup-plugin-fibjs-resolve'](),
        commonjs()
    ]
}).catch(e => console.error(e));

// generate code and map by `bundle.generate`
const { code, map } = await bundle.generate({
    format: 'cjs'
}).catch(e => console.error(e));

// write bundled result with `bundle.write`
await bundle.write({
    file: path.resolve(__dirname, './dist/bundle.js'),
    format: 'cjs'
}).catch(e => console.error(e));

view more demos in demo/

CLI

would be supported in the future.

APIs

  • utils.vbox.getCustomizedVBox (myModules: any, myFallback: Function = recommendedVBoxModuleFallback)

get 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.

Virtual 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.

Some 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

For 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.

default patched modules is recommendedVBoxModules, see details in src/utils/vbox.ts.

  • utils.vbox.recommendedVBoxModules

see details in src/utils/vbox.ts

  • utils.vbox.recommendedVBoxModuleFallback

see details in src/utils/vbox.ts

Internal Plugins

rollup-plugin-fibjs-resolve

rollup-plugin-node-resolve's fibjs version.

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.

fibjs'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.

type: fibjsResolve(options: RollupPluginFibjsResolveOptions = {})

const path = require('path');
const { default: rollup, plugins } = require('../../')

const commonjs = require('rollup-plugin-commonjs');

const bundle = await rollup.rollup({
    input: path.resolve(__dirname, './index.js'),
    external: ['coroutine'],
    plugins: [
        plugins['rollup-plugin-fibjs-resolve'](),
        // use it with rollup-plugin-commonjs
        commonjs()
    ]
}).catch(e => console.error(e));

rollup-plugin-uglify-js

uglify-js wrapper for rollup on fibjs.

const path = require('path');
const { default: rollup, plugins } = require('../../')

const buble = require('rollup-plugin-buble')
const commonjs = require('rollup-plugin-commonjs');

const bundle = await rollup.rollup({
    input: path.resolve(__dirname, './index.ts'),
    external: ['coroutine'],
    plugins: [
        plugins['rollup-plugin-fibjs-resolve'](),
        // transpile es201X feature such as template string
        buble(),
        commonjs(),
        plugins['rollup-plugin-uglify-js']()
    ]
}).catch(e => console.error(e));

rollup-plugin-uglify-es

Started from 0.4.0

uglify-es wrapper for rollup on fibjs.

const path = require('path');
const { default: rollup, plugins } = require('../../')

const commonjs = require('rollup-plugin-commonjs');

const bundle = await rollup.rollup({
    input: path.resolve(__dirname, './index.js'),
    external: ['coroutine'],
    plugins: [
        plugins['rollup-plugin-fibjs-resolve'](),
        commonjs(),
        plugins['rollup-plugin-uglify-es']()
    ]
}).catch(e => console.error(e));

rollup-plugin-babel-standalone(Beta)

use babel-standalone to transform javascript

const path = require('path');
const { default: rollup, plugins } = require('../../')

const commonjs = require('rollup-plugin-commonjs');

const bundle = await rollup.rollup({
    input: path.resolve(__dirname, './index.ts'),
    external: ['coroutine'],
    plugins: [
        plugins['rollup-plugin-fibjs-resolve'](),
        // transpile es201X feature such as template string
        plugins['rollup-plugin-babel-standalone']({
            // ...transform options, you can also set it in `$CWD/.babelrc` or `path.dirname(input)/.babelrc`
            presets: [
                ["es2015", { "modules": false }],
                // ...
            ]
        }),
        commonjs(),
        plugins['rollup-plugin-uglify-js']()
    ]
}).catch(e => console.error(e));

Document

rollupjs.org

Feature

  • <input checked="" disabled="" type="checkbox"> pure javascript bundle
    • <input disabled="" type="checkbox"> fibos
  • <input checked="" disabled="" type="checkbox"> server-side bundle
  • <input checked="" disabled="" type="checkbox"> frontend javacript bundle
    • <input checked="" disabled="" type="checkbox"> vue
    • <input disabled="" type="checkbox"> react
    • <input disabled="" type="checkbox"> angular
    • <input disabled="" type="checkbox"> jquery
    • <input disabled="" type="checkbox"> cheerio

Plugins Test Result

Plugin Name required version Is Valid? Comment
rollup-plugin-buble v0.2.0 ✔️ valid but it's not recommended to use with http.Server, it would lead to memory leak sometimes.
rollup-plugin-commonjs v0.2.0 ✔️
rollup-plugin-pug v0.2.0 ✔️
rollup-plugin-vue v0.2.0 ✔️
rollup-plugin-json v0.2.0 ✔️
rollup-plugin-graph -
rollup-plugin-typescript v0.2.2 ✔️ pass extensions: ['.ts'];
rollup compile typescript file(entry or module) automatically.
rollup-plugin-virtual v0.2.0 ✔️
rollup-plugin-uglify -
rollup-plugin-terser -
rollup-plugin-alias v0.2.0 ✔️

Development

fork this repo, run commands

npm i -D

# build
npm run build

# run test
npm run ci

License

GPL-3.0

Copyright (c) 2018-present, Richard

changelog

v0.4.0 / 2019-01-19

  • upgrade core, normalize code, disable vue-ssr use case due to bug of rollup-plugin-vue.
  • add doc about internal plugin['rollup-plugin-uglify-es'].
  • add internal plugin 'rollup-plugin-uglify-es'.
  • add demo/umd-custom-plugin1.
  • ts debuggable.
  • add simple server-side module package demo.
  • upgrade dependency.

v0.3.0 / 2018-11-25

  • Release v0.3.0
  • make @babel/standalone load-only-when-required.
  • add appveyor ci badget
  • typo normalization; normalize lib's export; add appveyor ci config.
  • fix test case's wrong async due to too fast executation.
  • little clean.
  • adjust test cases file structure.

v0.2.2 / 2018-11-13

  • Release v0.2.2
  • support rollup-plugin-typescript.

v0.2.1 / 2018-10-23

  • Release v0.2.1

v0.2.0 / 2018-10-23

  • Release v0.2.0
  • upgrade dependencies.
  • finish basic capability of internal plugin 'rollup-plugin-babel-standalone'.
  • [README.md]add plan declartion about 'rollup-plugin-babel-standalone'
  • add test case about rollup-plugin-buble.
  • [package.json]add 'prepublishOnly' scripts

v0.1.0 / 2018-10-01

  • Release v0.1.0
  • [pakcage.json] fix scripts 'ci'
  • sample code clean.
  • add internal plugin 'rollup-plugin-uglify-js'
  • add 'plugins' to exports, migrate API 'fibjsResolve' to it with name 'rollup-plugin-fibjs-resolve'
  • add 'lib/*' to .gitignore
  • add test about 'rollup-plugin-terser'
  • add test case about 'rollup-plugin-alias'
  • add test case about 'rollup-plugin-uglify'
  • remove uesage of 'rollup-plugin-typescript' in test case.
  • add plugins test cases about 'rollup-plugin-graph', 'rollup-plugin-json', 'rollup-plugin-virtual'
  • update some test cases.
  • update .npmignore
  • [README.md] little fix
  • [README.md] little fix
  • add npm and travis badgets

v0.0.1 / 2018-09-09

  • Release v0.0.1
  • do some fix, add 'src' to .npmignore
  • update README.md
  • and add traivs config.
  • Merge pull request #1 from fibjs/dev
  • add demo/vue
  • feat: add exported member 'recommendedVBoxModules', 'recommendedVBoxModuleFallback', 'getCustomizedVBox' to support customize vbox.
  • add missing dependency module
  • finish basic capibility of packing, and normalize demo code.
  • Initial commit