Home

Awesome

Systematic

An opinionated, mostly framework-agnostic toolchain to package ES6 applications and libraries for the browser.

Features :

Installation

npm install systematic

The file structure expected for your application or library.

├── dist                  # what gets built
│   ├── app.settings.js
│   ├── bundle.js
│   ├── bundle.js.map
│   ├── translations.json
│   ├── an_asset.png
│   └── index.html
|
├── src                   # your code
│    ├── some_module/
|    |      ├── enums.js
|    |      ├── index.js
|    |      ├── index.spec.js
|    |      └── models.js
|    |
│    ├── utils.js
│    ├── index.html       # HTML entry point (applications)
│    ├── index.spec.js    # A test spec file
│    └── index.js         # JS entry point
|
├── webpack.config.js     # Webpack config, inherits systematic's
├── Makefile              # Your application's Makefile
└── systematic.ini        # systematic config

Config file

Makefile

Systematic uses GNU make. Create a Makefile at the root of your project, to import systematic commands:

include node_modules/systematic/mk/main.mk

# Your own commands

Entry points

Usage

make help gives a list of all commands.

Build

make serve to run a local server. make dist for a prod build.

Run tests

make test runs all test that match the test file pattern (default **/*tests.js). make livetest run test continuously, when a file changes.

Translations

make makemessages extract translations from your HTML and JS files using easygettext. The resulting .po files will be in /locale.

make translations generates a JSON file from them, located at dist/translations.json. It is automatically run with serve, dist and test.

You can then load them in your JS as an object:

import translations from 'dist/translations.json'`

Settings

make settings generates a file dist/app.settings.js from all INI files in src/settings/ if your project is an application. Settings files are processed in alphabetical order, the last one overriding the previous. It is automatically run with serve, dist and test.

The generated file dist/app.settings.js needs to be included in your index.html, since it will not be added by Webpack.

After the app is deployed, you might want to change the settings. This part is not handled by systematic, but we recommand to regenerate the settings from INI files. INI files are an ideal format, as it is not error prone, ensures only settings values are changed and no javascript is added.

Build profiles

From systematic.ini's profile option. For now, only the angular profile is supported on top of the natural vanilla profile.

Angular

Value : angular

Adds the ng-annotate Babel plugin.

VueJS

Value : vue

Adds translation management with the vue translation token.

Override Jest or Webpack config

It's possible to override the build or test config by adding config files at the root of the projet.

Building components

A component is halfway between a library and an application. You get to have an index.html page that is useful for development, but the dependencies aren't bundled with the final package, just like a library.

You also have the choice of having the component used directly within a page, without being required from within another JS application that goes through webpack.

In that regard, you have to pay attention to NOT import your dependencies using Webpack-based import feature and use the /* global _, L */ notation in your sources (use import in your tests, why not) so that your application will try and find those symbols on window; also, use the keep_dependency feature in your configuration file for any dependency yo uwant bundled with.

Building libraries

When building a library, we don't want the dependencies included in the bundle. It can cause version conflict with other packages or duplicated library imports.

Systematic will set all dependencies as webpack "externals", which means they have to be required by the app.

Polyfilling

Systematic uses Babel to transpile ES6, ES6+ code to plain ES5.

Polyfilling is still needed:

  1. For methods that can't be transpiled: when Babel can't guess the correct transpilation for instance.
console.log('blah'.repeat(2))  // Dynamically evaluated so transpilation lets it untouched
  1. To ensure expected ES6 features are present, whatever browser is used (Array.contains, for instance)

Applications

You have two solutions:

  1. Use babel-polyfill just like in tests. You have to include it in the app entry point, before any other import:
import 'babel-polyfill'

This has the advantage of simplicity and consistency across browsers but it pollutes the global scope quite broadly.

  1. Import what you need from core-js (on which babel-polyfill is built) on a per case basis:
import _repeat from 'core-js/library/fn/string/repeat';
const myStr = _repeat('blah', 2);

This method is preferred as you can precisely choose what's being added to the environment. But it's more tedious.

Libraries

Avoid a global polyfill as it modifies global entities such as "Function" or "String". Use precise imports from core-js as described above if needed.

Troubleshooting

Webpack's livereload is not working properly

You should probably allow more watchers on your machine, see how on webpack's doc.

License

MIT