A webpack plugin which allows code to be statically optimized for a particular context at bundling time.
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
For example in a webpack configuration, the map of features would look like this:
plguins:'foo': true'bar': false;;
This asserts feature
true and feature
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
The plugin detects structures like the following in transpiled TypeScript modules:
And will rewrite the code (given the static feature set above), like:
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:
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.
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.
To test this package, after ensuring all dependencies are installed, run the following command:
$ grunt test
TODO: If third-party code was used to write this library, make a list of project names and licenses here