Skip to content
This repository was archived by the owner on Jan 20, 2019. It is now read-only.

Commit 18dc017

Browse files
committed
Ember CLI: Production code stripping
1 parent 26787f0 commit 18dc017

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
- Start Date: 2016-04-06
2+
- RFC PR: (leave this empty)
3+
- ember-cli Issue: (leave this empty)
4+
5+
# Summary
6+
7+
A number of Ember framework function calls are no-ops in production. Ember CLI should strip these no-op function invocations from production builds by default.
8+
9+
# Motivation
10+
11+
Removing code that isn't required in production results in smaller and faster applications.
12+
13+
# Detailed design
14+
15+
The following framework function calls will be removed from ember-cli production builds by default:
16+
17+
* [`Ember.assert`](http://emberjs.com/api/#method_assert)
18+
* [`Ember.debug`](http://emberjs.com/api/#method_debug)
19+
* [`Ember.deprecate`](http://emberjs.com/api/#method_deprecate)
20+
* [`Ember.info`](http://emberjs.com/api/#method_info)
21+
* [`Ember.runInDebug`](http://emberjs.com/api/#method_runInDebug)
22+
* [`Ember.warn`](http://emberjs.com/api/#method_warn)
23+
24+
The API documentation will be updated where necessary to indicate that these function calls will be stripped from production builds.
25+
26+
A babel plugin will execute the removal of these function calls based on provided configuration. The plugin will affect the code of the current app or addon only and won't affect code in child or grandchild addons. As this change becomes part of the default ember-cli configuration, addons will adopt the code stripping as they upgrade to newer ember-cli versions.
27+
28+
The plugin configuration will define an array of modules or global functions to remove. Here's an example of what this configuration might look like:
29+
30+
```js
31+
{
32+
removals: [
33+
{
34+
module: 'ember', //eg. import Em from 'ember';
35+
paths: [
36+
'assert', //Em.assert will be removed
37+
'debug', //Em.debug will be removed
38+
'a.b.c' //Em.a.b.c will be removed
39+
]
40+
}, {
41+
global: 'Ember',
42+
paths: [
43+
'deprecate' //Ember.deprecate will be removed
44+
]
45+
}, {
46+
paths: [
47+
'console.log' //console.log will be removed
48+
]
49+
}
50+
]
51+
}
52+
```
53+
54+
The plugin will support removal of destructured and reassigned invocations of these functions and will support both Babel 5 and 6.
55+
56+
An app or addon can disable the code removal by removing the babel plugin.
57+
58+
# How We Teach This
59+
60+
This change doesn't bring any new functionality. Other than updating the Ember API docs, we don't need to make guide or other documentation changes. At the time of releasing, we may want to point out the possible side effects in a release blog post (see the _Drawbacks_ section below).
61+
62+
If we want to expose the configuration options so that application authors can customize the settings, we can include a new section in the Ember CLI docs.
63+
64+
# Drawbacks
65+
66+
This may introduce an unexpected change in production builds as arguments that have side effects will no longer be executed. For example:
67+
68+
```js
69+
Ember.assert('Some assertion', someSideEffect());
70+
```
71+
72+
Currently, the `someSideEffect` function will be executed in production. When this RFC lands, it won't.
73+
74+
# Alternatives
75+
76+
An Ember addon could provide opt-in function stripping for applications that want it. If this RFC isn't deemed a good default for Ember CLI, that option should be explored.

0 commit comments

Comments
 (0)