dojo / cli-build-webpack

🚀 **DEPRECATED** Dojo 2 - cli command for building applications
http://dojo.io
Other
4 stars 19 forks source link

Add static has build optimization #172

Closed kitsonk closed 7 years ago

kitsonk commented 7 years ago

Type: feature

The following has been addressed in the PR:

Description:

This PR allows build optimization using the has feature detection library. During the build process, any static features that have been asserted are used to replace call expressions that look something like has('feature'). For example, if feature foo was set to true as a static flag, this code:

import has from `@dojo/has/has`;

if (has('foo')) {
  console.log('has foo');
}
else {
  console.log('does not have foo');
}

Would be transformed to this:

import has from `@dojo/has/has`;

if (true) {
  console.log('has foo');
}
else {
  console.log('does not have foo');
}

Then further during the build process, if the build is being minified, uglify will detect the dead code and rewrite it further to something like:

console.log('has foo');

At the command line, users are abstracted from individual flags, and instead supply a set of feature flags they wish to use. The supported sets are located in src/features/*.json. These are specified by the user by setting the -f or --feature flag on the CLI. Multiple feature sets are combined to produce the largest set where the values do not conflict. For example es6-promise is true on chrome but false on ie11. If chrome and ie11 were specified, the values would conflict and this feature would not be statically bound.

A user supplying multiple platforms would look something like this:

$ dojo build -f chrome safari firefox

Which would produce a build that is statically built with features that are common between Chrome, Safari, Firefox.

At the moment, most of the shim library isn't written to have polyfill code within has() guard blocks, therefore it doesn't get removed from the build when the native feature is statically expressed. We will need to revisit those modules in order to create something that builds optimally.

Todo:

Resolves #142

kitsonk commented 7 years ago

Two thoughts on this...

kitsonk commented 7 years ago

This now requires dojo/shim#101 for the sets of features to actually be effective.