You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h2><aname="hasjs">Integration with has.js</a><spanclass="sectionMark">§ 8</span></h2>
228
+
229
+
<p><ahref="https://github.com/phiggins42/has.js">has.js</a> is a great tool to that adds easy feature detection for your project. There is some optimizer support for optimizing code paths for has.js tests.</p>
230
+
231
+
<p>If your code uses tests like the following:</p>
232
+
233
+
<pre><code>
234
+
if (has("someThing")) {
235
+
//use native someThing
236
+
} else {
237
+
//do some workaround
238
+
}
239
+
</code></pre>
240
+
241
+
<p>You can define a <b>has</b> object in the build config with true or false values for some has() tests, and the optmizer will replace the has() test with the true or false value.</p>
242
+
243
+
<p>If your build profile looked like so:</p>
244
+
245
+
<pre><code>
246
+
({
247
+
baseUrl: "./",
248
+
name: "hasTestModule",
249
+
out: "builds/hasTestModule.js",
250
+
has: {
251
+
someThing: true
252
+
}
253
+
})
254
+
</code></pre>
255
+
256
+
<p>Then the optimizer will transform the above code sample to:</p>
257
+
258
+
<pre><code>
259
+
if (true) {
260
+
//use native someThing
261
+
} else {
262
+
//do some workaround
263
+
}
264
+
</code></pre>
265
+
266
+
<p>Then, if you use the default <b>optimize</b> setting that uses Closure Compiler, Closure Compiler will optimize out the dead code branch! So you can do custom builds of your code that are optimized for a set of has() tests.</p>
<p>There is an <ahref="http://github.com/jrburke/requirejs/blob/master/build/example.build.js">example.build.js</a> file in the requirejs/build directory that details all of the allowed optimization tool configuration options.</p>
0 commit comments