Skip to content

Commit 6bc1081

Browse files
authored
Merge pull request #399 from kratiahuja/update-readme
Update README with new `ember s` instructions and build hooks.
2 parents 1ba0854 + 9e51a87 commit 6bc1081

2 files changed

Lines changed: 61 additions & 42 deletions

File tree

README.md

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ your production app and have FastBoot work.
2121

2222
## Installation
2323

24-
FastBoot requires Ember 2.3 or higher.
24+
FastBoot requires Ember 2.3 or higher. It is also preferable that your app is running `ember-cli` 2.12.0 and higher.
2525

2626
From within your Ember CLI application, run the following command:
2727

@@ -31,33 +31,38 @@ ember install ember-cli-fastboot
3131

3232
## Running
3333

34-
* `ember fastboot --serve-assets`
35-
* Visit your app at `http://localhost:3000`.
34+
If your app is running `ember-cli` 2.12.0-beta.1+ you can run as follows:
35+
36+
* `ember serve`
37+
* Visit your app at `http://localhost:42000`
3638

3739
You may be shocked to learn that minified code runs faster in Node than
3840
non-minified code, so you will probably want to run the production
3941
environment build for anything "serious."
4042

4143
```
42-
ember fastboot --environment production
44+
ember serve --environment production
4345
```
4446

4547
You can also specify the port (default is 3000):
4648

4749
```
48-
ember fastboot --port 8088
50+
ember serve --port 8088
4951
```
5052

51-
See `ember help fastboot` for more.
53+
See `ember help` for more.
5254

53-
### With `ember-cli` version 2.12.0-beta.1 and above
54-
If your app is running ember-cli v2.12.0-beta.1+, you can just use `ember serve` instead of `ember fastboot --serve-assets` and visit at `http://localhost:4200/`.
55+
### Disabling FastBoot with `ember serve`
5556

5657
Optionally you can even disable the fastboot serving at runtime using the `fastboot` query parameter. Example to turn off fastboot serving,
5758
visit your app at `http://localhost:4200/?fastboot=false`. If you want to turn on fastboot serving again, simply visit at `http://localhost:4200/?fastboot=true` or `http://localhost:4200/`.
5859

5960
You can even disable serving fastboot with `ember serve` using an environment flag: `FASTBOOT_DISABLED=true ember serve`. If you have disabled building fastboot assets using the same flag as described [here](https://github.com/ember-fastboot/ember-cli-fastboot#double-build-times-and-no-incremental-builds), remember to also disable serving fastboot assets when using `ember serve`.
6061

62+
### Deprecation of `ember fastboot`
63+
64+
`ember fastboot` which was earlier required to run your app in FastBoot is now deprecated and is removed in the RC builds of `ember-cli-fastboot`. With FastBoot 1.0 to be released soon, this command will no longer exists and will be replaced by `ember serve`. It is recommended that your upgrade the `ember-cli` version of your app to be 2.12.0 and above.
65+
6166
## Using Node/npm Dependencies
6267

6368
### Whitelisting Packages
@@ -347,28 +352,38 @@ export default Ember.Route.extend({
347352
});
348353
```
349354

350-
## Disabling incompatible dependencies
355+
## Build Hooks for FastBoot
356+
357+
### Disabling incompatible dependencies
351358

352359
There are two places where the inclusion of incompatible JavaScript libraries could
353360
occur:
354361

355362
1. `app.import` in the application's `ember-cli-build.js`
356363
2. `app.import` in an addon's `included` hook
357364

358-
`ember-cli-fastboot` sets the `EMBER_CLI_FASTBOOT` environment variable when it is
359-
building the FastBoot version of the application. You can use this to prevent the
360-
inclusion of the library at build time:
365+
You can include the incompatible Javascript libraries by wrapping them with a `FastBoot` variable check. In the browser, `FastBoot` global variable is not defined.
361366

362367
```js
363-
if (!process.env.EMBER_CLI_FASTBOOT) {
364-
// This will only be included in the browser build
365-
app.import('some/jquery.plugin.js')
368+
var map = require('broccoli-stew').map;
369+
370+
treeForVendor(defaultTree) {
371+
var browserVendorLib = new Funnel(...);
372+
373+
browserVendorLib = map(browserVendorLib, (content) => `if (typeof FastBoot === 'undefined') { ${content} }`);
374+
375+
return new mergeTrees([defaultTree, browserVendorLib]);
376+
}
377+
378+
included() {
379+
// this file will be loaded in FastBoot but will not be eval'd
380+
app.import('vendor/<browserLibName>.js');
366381
}
367382
```
368383

369-
*Note*: This is soon going to be deprecated. See [this issue](https://github.com/ember-fastboot/ember-cli-fastboot/issues/360).
384+
*Note*: `ember-cli-fastboot` will no longer provide the `EMBER_CLI_FASTBOOT` environment variable to differentiate browser and fastboot builds with rc builds and FastBoot 1.0 and above.
370385

371-
## Loading additional assets in FastBoot environment
386+
### Loading additional assets in FastBoot environment
372387

373388
Often addons require to load libraries that are specific to the FastBoot environment and only need to be loaded on the server side. This can include loading
374389
libraries before or after the vendor file is loaded in the sandbox and/or before or after the app file is loaded in the sandbox. Since the FastBoot manifest defines
@@ -397,9 +412,29 @@ updateFastBootManifest(manifest) {
397412
}
398413
```
399414

400-
*Note*: `process.env.EMBER_CLI_FASTBOOT` is soon going to be deprecated and [eventually removed](https://github.com/ember-fastboot/ember-cli-fastboot/issues/360).
415+
*Note*: `process.env.EMBER_CLI_FASTBOOT` will be removed in RC builds and FastBoot 1.0.
401416
Therefore, if you are relying on this environment variable to import something in the fastboot environment, you should instead use `updateFastBootManifest` hook.
402417

418+
### Conditionally include assets in FastBoot asset
419+
420+
Often your addon may need to conditionally include additional app trees based on ember version. Example, Ember changed an API and in order to have your addon be backward compatible for the API changes you want to include an asset when the ember version is x. For such usecases you could define the `treeForFastBoot` hook in your addon's `index.js` as below:
421+
422+
```js
423+
treeForFastBoot: function(tree) {
424+
let fastbootHtmlBarsTree;
425+
426+
// check the ember version and conditionally patch the DOM api
427+
if (this._getEmberVersion().lt('2.10.0-alpha.1')) {
428+
fastbootHtmlBarsTree = this.treeGenerator(path.resolve(__dirname, 'fastboot-app-lt-2-9'));
429+
return tree ? new MergeTrees([tree, fastbootHtmlBarsTree]) : fastbootHtmlBarsTree;
430+
}
431+
432+
return tree;
433+
},
434+
```
435+
436+
The `tree` is the additional fastboot asset that gets generated and contains the fastboot overrides.
437+
403438

404439
## Known Limitations
405440

@@ -428,22 +463,6 @@ Prototype extensions do not currently work across node "realms." Fastboot
428463
applications operate in two realms, a normal node environment and a [virtual machine](https://nodejs.org/api/vm.html). Passing objects that originated from the normal realm will not contain the extension methods
429464
inside of the sandbox environment. For this reason, it's encouraged to [disable prototype extensions](https://guides.emberjs.com/v2.4.0/configuring-ember/disabling-prototype-extensions/).
430465

431-
### Double build times and no incremental builds
432-
433-
Due to limitations in Ember CLI, builds take twice as long to generate the
434-
second set of FastBoot assets. This also means incremental builds with
435-
live reload don't work either. This aims to be resolved by FastBoot 1.0.
436-
In the mean time, we introduce a short-circuit environment flag to not do
437-
a FastBoot build:
438-
439-
```
440-
FASTBOOT_DISABLED=true ember build
441-
```
442-
443-
This is useful to keep your existing workflow while in development, while
444-
still being able to deploy FastBoot. This flag will be removed in FastBoot
445-
1.0.
446-
447466
## Troubleshooting
448467

449468
Because your app is now running in Node.js, not the browser, you'll
@@ -456,7 +475,7 @@ Enable verbose logging by running the FastBoot server with the following
456475
environment variables set:
457476

458477
```sh
459-
DEBUG=ember-cli-fastboot:* ember fastboot
478+
DEBUG=ember-cli-fastboot:* ember serve
460479
```
461480

462481
PRs adding or improving logging facilities are very welcome.
@@ -487,14 +506,10 @@ node-inspector --no-preload
487506

488507
Once the debug server is running, you'll want to start up the FastBoot
489508
server with Node in debug mode. One thing about debug mode: it makes
490-
everything much slower. Since the `ember fastboot` command does a full
491-
build when launched, this becomes agonizingly slow in debug mode.
492-
493-
Avoid the slowness by manually running the build in normal mode, then
494-
running FastBoot in debug mode without doing a build:
509+
everything much slower.
495510

496511
```sh
497-
ember build && node --debug-brk ./node_modules/.bin/ember fastboot --no-build
512+
ember build && node --debug-brk ./node_modules/.bin/ember serve
498513
```
499514

500515
This does a full rebuild and then starts the FastBoot server in debug
@@ -551,3 +566,7 @@ Run the tests with the `DEBUG` environment variable set to
551566
```sh
552567
DEBUG=fastboot-test npm test
553568
```
569+
570+
### Questions
571+
572+
Reach out to us in Ember community slack in the `#-fastboot` channel.

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ module.exports = {
9494
treeForFastBoot: function(tree) {
9595
let fastbootHtmlBarsTree;
9696

97-
// check the ember-cli version and conditionally patch the DOM api
97+
// check the ember version and conditionally patch the DOM api
9898
if (this._getEmberVersion().lt('2.10.0-alpha.1')) {
9999
fastbootHtmlBarsTree = this.treeGenerator(path.resolve(__dirname, 'fastboot-app-lt-2-9'));
100100
return tree ? new MergeTrees([tree, fastbootHtmlBarsTree]) : fastbootHtmlBarsTree;

0 commit comments

Comments
 (0)