Socket
Socket
Sign inDemoInstall

@dojo/static-optimize-plugin

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dojo/static-optimize-plugin

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


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

@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.

FAQs

Package last updated on 06 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc