Have ideas to improve npm?Join in the discussion! »

    workers-factory

    3.1.0 • Public • Published

    workers-factory

    Version npm License npm Downloads Build Status Dependencies

    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 --save

    Usage

    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#browserify the content is passed to the browserify.bundle method.
    • Webpack: Will read webpack.config.js from 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][wrhs.toml]
      [minify]
      minifier = 'terser'

    Test

    npm test

    Install

    npm i workers-factory

    DownloadsWeekly Downloads

    43

    Version

    3.1.0

    License

    MIT

    Unpacked Size

    270 kB

    Total Files

    48

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar