Nascent Political Miscreant

    This package has been deprecated

    Author message:

    @dojo/static-optimize-plugin is deprecated, please use @dojo/webpack-contrib instead

    @dojo/static-optimize-plugin
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.0 • Public • Published

    @dojo/static-optimize-plugin

    Build Status codecov npm version

    A webpack plugin which allows code to be statically optimized for a particular context at bundling time.

    Features

    For each module in a webpack build, the plugin will access the compilation, looking for code to optimize. It does this by walking the AST structure offered by webpack, making changes to the compilation.

    The plugin takes a map of static features, where the key is the name of the feature and the value is either true if the feature is present in that context, otherwise false.

    For example in a webpack configuration, the map of features would look like this:

    {
        plguins: [
            new StaticOptimizePlugin({
                'foo': true,
                'bar': false
            });
        ]
    };

    This asserts feature foo is true and feature bar is false. This map is then used in the features below.

    Dead Code Removal

    The plugin assumes that the @dojo/has API is being used in modules that are being compiled into a webpack bundle and attempts to rewrite calls to the has() API when it can see it has a statically asserted flag for that feature.

    The plugin detects structures like the following in transpiled TypeScript modules:

    import has from './has';
     
    if (has('foo')) {
        console.log('has foo');
    }
    else {
        console.log('doesn\'t have foo');
    }
     
    const bar = has('bar') ? 'has bar' : 'doesn\'t have bar';

    And will rewrite the code (given the static feature set above), like:

    import has from './has';
     
    if (true) {
        console.log('has foo');
    }
    else {
        console.log('doesn\'t have foo');
    }
     
    const bar = false ? 'has bar' : 'doesn\'t have bar';

    When this is minified via Uglify via webpack, Uglify looks for structures that can be optimised and would re-write it further to something like:

    import has from './has';
     
    console.log('has foo');
     
    const bar = 'doesn\'t have bar';

    Any features which are not statically asserted, are not re-written. This allows the code to determine at run-time if the feature is present.

    Elided Imports

    How do I use this package?

    TODO: Add appropriate usage and instruction guidelines

    How do I contribute?

    We appreciate your interest! Please see the Dojo 2 Meta Repository for the Contributing Guidelines and Style Guide.

    Testing

    To test this package, after ensuring all dependencies are installed, run the following command:

    $ grunt test

    Licensing information

    TODO: If third-party code was used to write this library, make a list of project names and licenses here

    © JS Foundation & contributors. New BSD and Apache 2.0 licenses.

    Keywords

    none

    Install

    npm i @dojo/static-optimize-plugin

    Homepage

    dojo.io

    DownloadsWeekly Downloads

    5

    Version

    0.1.0

    License

    (BSD-3-Clause OR Apache-2.0)

    Last publish

    Collaborators

    • rorticus
    • dylans
    • agubler
    • matt-gadd
    • tomdye
    • bitpshr