workers-factory v3.2.0
workers-factory
Utility functions to bundle and generate assets that can be served over the
web. The workers and minifiers are used by carpenterd-worker to
generate builds for Warehouse.ai.
Install
npm install workers-factory --saveUsage
const Factory = require('workers-factory');
//
// Run a webpack build
//
Factory.webpack(options, (err, files) => {
// returns an array of files that were output.
});We assume options.content is a path to a fully built (npm installed)
tar.gz.
API
Worker will trigger the factory to go through the following methods in series. The factory line will always have to complete in full for a build to be considered done.
| Factory step | Execution |
|---|---|
unpack | Untar the contents of the tarball |
init | Read package.json and configure factory |
exists | Check if entry file exists |
read | Read the entry file |
assemble | Execute the builder implemented run |
minify | Minify the content for env={ test, prod } |
pack | Create a tarball of contents |
clean | Remove temporary build directory |
Note: Factory.assemble will execute the exported run function from each worker.
It will callback the next step in the chain with a Buffer of content if
it completes without errors.
Workers
- Browserify: Create a bundle using Browserify. Configured
through
package.json#browserifythe content is passed to thebrowserify.bundlemethod. - Webpack: Will read
webpack.config.jsfrom tarball content and execute the bundled Webpack to generate a build of assets.
Minification
Based on the file extension one of the following minifiers is available to
minify the asset content. Configuration for both JS minifiers can be supplied
through wrhs.toml using the minify property.
- CleanCSS: Minifies CSS using CleanCSS, special comments are removed and a sourcemap is generated by default.
- Minimize: Minifies HTML using minimize.
- Uglifyjs: Minify JS using Uglifyjs.
- Terser: Minify JS (containing ES6) using Terser. Requires opt-in in
through
wrhs.toml[minify] minifier = 'terser'
Test
npm test3 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago