Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Commit

Permalink
Add static has build optimization (#172)
Browse files Browse the repository at this point in the history
Resolves #142
  • Loading branch information
kitsonk authored Aug 30, 2017
1 parent d2f976d commit 69b6213
Show file tree
Hide file tree
Showing 21 changed files with 634 additions and 61 deletions.
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module.exports = function(grunt) {
require('grunt-dojo2').initConfig(grunt, {
staticDefinitionFiles: [ '**/*.d.ts', '**/*.html', '**/*.md' ],
staticDefinitionFiles: [ '**/*.d.ts', '**/*.html', '**/*.md', '**/*.json' ],
copy: {
'staticDefinitionFiles-dev': {
expand: true,
cwd: 'src',
src: [ '**/*.md' ],
src: [ '**/*.md', '**/*.json' ],
dest: '<%= devDirectory %>/src/'
}
}
Expand Down
69 changes: 68 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

The official dojo 2 build command.

*WARNING* This is _beta_ software. While we do not anticipate significant changes to the API at this stage, we may feel the need to do so. This is not yet production ready, so you should use at your own risk.
*WARNING* This is _beta_ software. While we do not anticipate significant changes to the API at this stage, we may feel the need to do so. This is not yet production ready, so you should use at your own risk.

- [Usage](#usage)
- [Features](#features)
- [Building](#building)
- [Building a custom element](#building-a-custom-element)
- [Feature optimization](#feature-optimization)
- [Eject](#eject)
- [3rd party library integration](#interop-with-external-libraries)
- [How do I contribute?](#how-do-i-contribute)
Expand Down Expand Up @@ -81,6 +82,72 @@ If the source file does not follow the pattern `create[custom element]Element`,
dojo build webpack --element=src/path/to/element.ts --elementPrefix=the-special
```

### Feature optimization

This command supports the ability to optimize code based on statically asserted features. The tool can search the source code for modules that attempt to detect features using a [`@dojo/has`](https://github.com/dojo/has) type of API. By supplying a feature set (or sets) on the command line, the build will optimize code branches, making the code smaller and more efficient. This allows targeting of particular platforms.

When specifying multiple feature sets, if they do not align, the tool will not optimize the source code for these feature sets and will instead continue to leave that feature to be detected at run-time.

From the command line, the feature sets are provided to the `-f` or `--feature` argument. The available feature sets are aligned to platforms. The currently available feature sets are:

|Feature Set|Description|
|-|-|
|`android`|This feature set represents Android 5+ with integrated Chrome browser. *Note* it is not suitable for Android 4.4.|
|`chrome`|This feature set represents Chrome 59+ or Opera 46+[<sup>1</sup>](#note-1)|
|`edge`|This feature set represents Edge 15+[<sup>1</sup>](#note-1)|
|`firefox`|This feature set represents Firefox 54+[<sup>1</sup>](#note-1)|
|`ie11`|This feature set represents Internet Explorer 11|
|`ios`|This feature set represents iOS 10.3+[<sup>2</sup>](#note-2)|
|`node`|This feature set represents Node.js 6/7[<sup>2</sup>](#note-2)|
|`node8`|This feature set represents Node.js 8+|
|`safari`|This feature set represents Safari 10+[<sup>2</sup>](#note-2)|

<span id="note-1">[1]:</span> Many of these features were present in earlier versions, but the specific version was the GA release at the time of writing when this was validated.

<span id="note-2">[2]:</span> At least one of the features was not present in previous releases.

Instead of _sniffing_ for a browser, the feature sets are a static set of features that are expressed as flags in the `@dojo` modules. The current set of flags are:

|Flag|Description|
|-|-|
|arraybuffer|Supports `ArrayBuffer`|
|blob|Supports the `blob` response type for XHR requests|
|dom-mutationobserver|Supports MutationObserver|
|es-observable|Supports ES Observable proposal|
|es2017-object|Supports ES2017 Object features|
|es2017-string|Supports ES2017 String features|
|es6-array|Supports ES2015 Array features (except `.fill`)|
|es6-array-fill|Supports a non-buggy version of `Array.prototype.fill()`|
|es6-map|Supports ES2015 Map|
|es6-math|Supports ES2015 Math features (except `.imul`|
|es6-math-imul|Supports a non-buggy version of `Math.imul()`|
|es6-object|Supports ES2015 Object features|
|es6-promise|Supports ES2015 Promise|
|es6-set|Supports ES2015 Set|
|es6-string|Supports ES2015 String features (except `.raw()`|
|es6-string-raw|Supports a non-buggy version of `String.raw()`|
|es6-symbol|Supports ES2015 Symbol|
|es6-weakmap|Supports ES2015 WeakMap|
|es7-array|Supports ES2016 Array features|
|fetch|Supports the `fetch` API|
|filereader|Supports the FileReader API|
|float32array|Supports the Float32Array API|
|formdata|Supports form data|
|host-node|Is a NodeJS Host|
|host-browser|Is a Browser Host|
|microtasks|Supports an API that allows scheduling of microtasks|
|node-buffer|Supports the Node.JS Buffer API|
|raf|Supports the `requestAnimationFrame` API|
|setimmediate|Supports the `setImmediate` API|
|xhr|Supports XMLHTTPRequest API|
|xhr2|Supports the XMLHTTPRequest 2 API|

An example of generating a build that _hardwires_ features for Microsoft Edge and Chrome, you would use the following on the command line:

```shell
$ dojo build -f edge chrome
```

### Eject

Ejecting `@dojo/cli-build-webpack` will produce a `config/build-webpack/webpack.config.js` file. You can run build using webpack with:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@dojo/has": "next",
"@dojo/i18n": "next",
"@dojo/shim": "next",
"@dojo/static-optimize-plugin": "next",
"auto-require-webpack-plugin": "1.0.1",
"bundle-loader": "0.5.5",
"copy-webpack-plugin": "4.0.1",
Expand Down
35 changes: 35 additions & 0 deletions src/features/android.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"arraybuffer": true,
"blob": true,
"dom-mutationobserver": true,
"es-observable": false,
"es2017-object": true,
"es2017-string": true,
"es6-array": true,
"es6-array-fill": true,
"es6-map": true,
"es6-math": true,
"es6-math-imul": true,
"es6-object": true,
"es6-promise": true,
"es6-set": true,
"es6-string": true,
"es6-string-raw": true,
"es6-symbol": true,
"es6-weakmap": true,
"es7-array": true,
"fetch": true,
"filereader": true,
"float32array": true,
"formdata": true,
"host-node": false,
"host-browser": true,
"microtasks": true,
"node-buffer": false,
"object-assign": true,
"postmessage": true,
"raf": true,
"setimmediate": false,
"xhr": true,
"xhr2": true
}
35 changes: 35 additions & 0 deletions src/features/chrome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"arraybuffer": true,
"blob": true,
"dom-mutationobserver": true,
"es-observable": false,
"es2017-object": true,
"es2017-string": true,
"es6-array": true,
"es6-array-fill": true,
"es6-map": true,
"es6-math": true,
"es6-math-imul": true,
"es6-object": true,
"es6-promise": true,
"es6-set": true,
"es6-string": true,
"es6-string-raw": true,
"es6-symbol": true,
"es6-weakmap": true,
"es7-array": true,
"fetch": true,
"filereader": true,
"float32array": true,
"formdata": true,
"host-node": false,
"host-browser": true,
"microtasks": true,
"node-buffer": false,
"object-assign": true,
"postmessage": true,
"raf": true,
"setimmediate": false,
"xhr": true,
"xhr2": true
}
35 changes: 35 additions & 0 deletions src/features/edge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"arraybuffer": true,
"blob": true,
"dom-mutationobserver": true,
"es-observable": false,
"es2017-object": true,
"es2017-string": true,
"es6-array": true,
"es6-array-fill": true,
"es6-map": true,
"es6-math": true,
"es6-math-imul": true,
"es6-object": true,
"es6-promise": true,
"es6-set": true,
"es6-string": true,
"es6-string-raw": true,
"es6-symbol": true,
"es6-weakmap": true,
"es7-array": true,
"fetch": true,
"filereader": true,
"float32array": true,
"formdata": true,
"host-node": false,
"host-browser": true,
"microtasks": true,
"node-buffer": false,
"object-assign": true,
"postmessage": true,
"raf": true,
"setimmediate": true,
"xhr": true,
"xhr2": true
}
35 changes: 35 additions & 0 deletions src/features/firefox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"arraybuffer": true,
"blob": true,
"dom-mutationobserver": true,
"es-observable": false,
"es2017-object": true,
"es2017-string": true,
"es6-array": true,
"es6-array-fill": true,
"es6-map": true,
"es6-math": true,
"es6-math-imul": true,
"es6-object": true,
"es6-promise": true,
"es6-set": true,
"es6-string": true,
"es6-string-raw": true,
"es6-symbol": true,
"es6-weakmap": true,
"es7-array": true,
"fetch": true,
"filereader": true,
"float32array": true,
"formdata": true,
"host-node": false,
"host-browser": true,
"microtasks": true,
"node-buffer": false,
"object-assign": true,
"postmessage": true,
"raf": true,
"setimmediate": false,
"xhr": true,
"xhr2": true
}
35 changes: 35 additions & 0 deletions src/features/ie11.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"arraybuffer": true,
"blob": true,
"dom-mutationobserver": false,
"es-observable": false,
"es2017-object": false,
"es2017-string": false,
"es6-array": false,
"es6-array-fill": false,
"es6-map": false,
"es6-math": false,
"es6-math-imul": false,
"es6-object": false,
"es6-promise": false,
"es6-set": false,
"es6-string": false,
"es6-string-raw": false,
"es6-symbol": false,
"es6-weakmap": false,
"es7-array": false,
"fetch": false,
"filereader": true,
"float32array": true,
"formdata": false,
"host-node": false,
"host-browser": true,
"microtasks": true,
"node-buffer": false,
"object-assign": false,
"postmessage": true,
"raf": true,
"setimmediate": true,
"xhr": true,
"xhr2": true
}
35 changes: 35 additions & 0 deletions src/features/ios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"arraybuffer": true,
"blob": true,
"dom-mutationobserver": true,
"es-observable": false,
"es2017-object": false,
"es2017-string": false,
"es6-array": true,
"es6-array-fill": true,
"es6-map": true,
"es6-math": true,
"es6-math-imul": true,
"es6-object": true,
"es6-promise": true,
"es6-set": true,
"es6-string": true,
"es6-string-raw": true,
"es6-symbol": true,
"es6-weakmap": true,
"es7-array": false,
"fetch": true,
"filereader": true,
"float32array": true,
"formdata": true,
"host-node": false,
"host-browser": true,
"microtasks": true,
"node-buffer": false,
"object-assign": true,
"postmessage": true,
"raf": true,
"setimmediate": false,
"xhr": true,
"xhr2": true
}
35 changes: 35 additions & 0 deletions src/features/node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"arraybuffer": true,
"blob": true,
"dom-mutationobserver": false,
"es-observable": false,
"es2017-object": false,
"es2017-string": false,
"es6-array": true,
"es6-array-fill": true,
"es6-map": true,
"es6-math": true,
"es6-math-imul": true,
"es6-object": true,
"es6-promise": true,
"es6-set": true,
"es6-string": true,
"es6-string-raw": true,
"es6-symbol": true,
"es6-weakmap": true,
"es7-array": true,
"fetch": false,
"filereader": false,
"float32array": true,
"formdata": false,
"host-node": true,
"host-browser": false,
"microtasks": true,
"node-buffer": true,
"object-assign": true,
"postmessage": false,
"raf": false,
"setimmediate": true,
"xhr": false,
"xhr2": false
}
35 changes: 35 additions & 0 deletions src/features/node8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"arraybuffer": true,
"blob": true,
"dom-mutationobserver": false,
"es-observable": false,
"es2017-object": true,
"es2017-string": true,
"es6-array": true,
"es6-array-fill": true,
"es6-map": true,
"es6-math": true,
"es6-math-imul": true,
"es6-object": true,
"es6-promise": true,
"es6-set": true,
"es6-string": true,
"es6-string-raw": true,
"es6-symbol": true,
"es6-weakmap": true,
"es7-array": true,
"fetch": false,
"filereader": false,
"float32array": true,
"formdata": false,
"host-node": true,
"host-browser": false,
"microtasks": true,
"node-buffer": true,
"object-assign": true,
"postmessage": false,
"raf": false,
"setimmediate": true,
"xhr": false,
"xhr2": false
}
Loading

0 comments on commit 69b6213

Please sign in to comment.