Note: File references are relative to ./packages/plexus
; ./
refers to ./packages/plexus
.
The package is implemented in TypeScript and must be compiled to JavaScript.
There are three build scenarios and one pre-step common to all of them.
Pre-step:
- Bundle
./src/LayoutManager/layout.worker.tsx
to a UMD module which can initialize aWebWorker
from aBlob
URL
Build scenarios:
- Production ES modules
- This is the project's default export as
./lib/index.js
. This build is not bundled and therefore does not use Webpack.
- This is the project's default export as
- Production UMD module
- Webpack dev server
- Runs
./demo/src/index.tsx
which has a few example graphs.
- Runs
The pre-step, which they all require, is to bundle ./src/LayoutManager/layout.worker.tsx
via the worker-loader
Webpack loader.
Babel is used to transpile the TypeScript for all scenarios and the pre-step. See babel.config.js
for specifics.
The production ES module build is not bundled and therefore does not use Webpack.
Webpack is used to:
- Bundle
./src/LayoutManager/layout.worker.tsx
so we can have aWebWorker
without forcing folks to deal with an additional JavaScript asset - Bundle the production UMD module
- Run the Webpack dev server during development
./webpack-factory.js
is used to generate the Webpack configurations for each scenario.
Compiling TypeScript via Babel does not allow for type declarations to be generated. So, tsc
is used with ./tsconfig.json
to generate the type defs.
This only applies to the ES module production build, output to ./lib
.
Note: ./tsconfig.json
does not extend ../../tsconfig.json
.
./src/LayoutManager/layout.worker.tsx
is intended to be loaded as a WebWorker
. To be able to load it as a Worker
without requiring an extra JS file, Webpack and the worker-loader
loader are used to bundle it into a UMD module, ./src/LayoutManager/layout.worker.bundled.js
.
Within the UMD module, layout.worker.tsx
(and everything bundled into it) is turned into a Blob
URL that's used to initialize a WebWorker
.
The resultant UMD module can be initialized as a class:
import LayoutWorker from './layout.worker.bundled';
const leWorker = new LayoutWorker();
leWorker.postMessage(...);
It's all fun and games until type checking loses an eye.
To make sure we don't end up with an implicit any
, layout.worker.bundled.d.ts
provides a type declaration:
class LayoutWorker extends Worker { ... }
build
— Generates the UMD bundle and ES module production buildsprepublishOnly
— Executed afteryarn install
is run in the project root; runs thebuild
scriptstart
— Starts the Webpack dev server and watches all files, includinglayout.worker
The _tasks/*
scripts are not intended to be run, directly.
_tasks/clean/*
- Remove generated files
_tasks/bundle-worker
- Generates the
layout.worker
UMD bundle
- Generates the
_tasks/build/*
- Generates the production ES and UMD builds
_tasks/dev-server
- Starts the Webpack dev server
This specific version of viz.js is used to avoid a regression. Meanwhile, looks like 2.x.x
has recovered a lot of ground; GitHub ticket to upgrade.
Jest is not actually be used, yet. Present as a placeholder. (Ticket)
Configures ESLint for TypeScript. ESLint is executed from the project root, but this file is merged with the project root .eslintrc.js
and overrides where there is overlap.
prettier/@typescript-eslint
needs to be last in the extends
so it overrides the formatting rules from plugin:@typescript-eslint/recommended
.
Uses @typescript-eslint/parser
as the parser.
The tsconfigRootDir: '.'
refers to the project root because that is where ESLint is executed, from. And, the tsconfig.json
referred to by ./.eslintrc.js
is that in the project root.