Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

chore: Use bili bundler. #333

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

hastebrot
Copy link

@hastebrot hastebrot commented May 12, 2019

This replaces Webpack with Bili (a bundler based on Rollup).

Main reason is that I want to use tcomb on ObservableHQ (for notebook-based programming) via unpkg.com. It currently only includes CommonJS bundles and the dist/ directory is missing: (see: https://unpkg.com/[email protected]/).

Screenshot 2019-05-12 at 11 05 19

I've added/modified entries in package.json (which seems a sane default) to let unpkg.com and jsdelivr.com know where to find the bundles. Adapted from https://github.com/immerjs/immer/blob/v3.1.1/package.json. The umd:main output is minified for use in browsers.

{
  "main": "dist/tcomb.js",
  "module": "dist/tcomb.module.js",
  "umd:main": "dist/tcomb.umd.js",
}

It adds a bili.config.ts where you can e.g. configure the formats. The apidocs (https://bili.egoist.sh/api/globals.html#format) say you can additionally use "cjs-min" | "es-min" | "esm-min" | "umd-min" | "iife-min" | "amd-min" | "system-min". Adapted from https://github.com/immerjs/immer/blob/v3.1.1/bili.config.ts.

import { Config } from "bili";

const config: Config = {
  input: {
    tcomb: "index.js"
  },
  output: {
    format: ["cjs", "umd", "esm"],
    moduleName: "tcomb",
    sourceMap: true,
    sourceMapExcludeSources: true
  },

Finally I've changed package.json scripts to have build and test. I think unpkg.com needs it to process the bundles and put it into dist/ for each release. I've run npm run build and npm run test and it works. Do we want to add both steps to .travis.yml?

  "scripts": {
    "build": "rimraf dist/ && bili",
    "test": "npm run lint && mocha && npm run typescript && npm run perf",
    "lint": "eslint index.js lib test",
    "perf": "node ./perf/perf",
    "typescript": "tsc --noEmit tcomb-tests.ts"
  },

I've also tested microbundle but Bili was better documented and configurable. Not relevant for tcomb bundle process but worth mentioning: It also does not leave annoying build cache directories used by rollup-plugin-typescript2 (this can be also configured). Also iife output option is documented and does not clash with cjs output configuration like in microbundle. Bili is much smaller than microbundle (see "Bili vs Microbundle" issue at egoist/bili#163).

@hastebrot
Copy link
Author

hastebrot commented May 12, 2019

I guess main in package.json has to be changed back to index.js (from dist/tcomb.js), since we are not running npm run build on every npm publish.

@hastebrot
Copy link
Author

Done. This is good for review now.

Screenshot 2019-05-12 at 11 37 49

@hastebrot hastebrot marked this pull request as ready for review May 12, 2019 09:39
@hastebrot
Copy link
Author

So, probably we want to have tcomb.js for development and tcomb.min.js for production (see: https://github.com/gcanti/tcomb/tree/v3.2.29#how-to-build-a-standalone-bundle).

@hastebrot
Copy link
Author

I think we can decrease the bundle size more. Seems Webpack creates smaller bundles than Bili.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant