forked from miragejs/ember-cli-mirage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Public API to query if files are included in build
Implement a public API (using the environment config) for addons to determine if mirage's files are included in the build, so they can decide whether to include any mirage-dependent files. Fixes miragejs#2166
- Loading branch information
1 parent
a9b38e7
commit d653001
Showing
4 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
tests/dummy/app/pods/docs/advanced/supplying-helpers-from-addons/template.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Supplying helpers from addons | ||
|
||
Some addons supply Mirage models, route functions, or other code to help applications set up their Mirage configuration. The build's target environment and the [environment options](#environment-options) together determine whether Mirage's code will be included in the build or not, so addons that supply code that imports modules from mirage have to include or exclude that code accordingly. | ||
|
||
To support this, Mirage writes an `includedInBuild` value to `ENV['ember-cli-mirage']` that other addons can read. To take advantage of this in your addon, you need to first make sure that your addon's hooks are called _after_ `ember-cli-mirage`'s by putting the following in your addon's `package.json`: | ||
|
||
```diff | ||
"ember-addon": { | ||
"configPath": "tests/dummy/config", | ||
+ "after": [ | ||
+ "ember-cli-mirage" | ||
+ ], | ||
} | ||
``` | ||
|
||
Then you can look for the `includedInBuild` property of `ENV['ember-cli-mirage']` (being careful to not assume that `ENV['ember-cli-mirage']` is present, since it won't be if `ember-cli-mirage` isn't installed in the consuming application): | ||
|
||
```js | ||
included(app) { | ||
this.mirageConfig = config['ember-cli-mirage'] || {}; | ||
this._super.included.apply(this, arguments); | ||
}, | ||
|
||
treeForAddon() { | ||
let tree = this._super(...arguments); | ||
if (!mirageConfig.includedInBuild) { | ||
// Exclude mirage-dependent files, e.g. use broccol-funnel to exclude | ||
// files in `addon/mirage/`: | ||
// | ||
// const removeFile = require('broccoli-funnel'); | ||
// tree = funnel(tree, { | ||
// exclude: 'mirage/**/*.js', | ||
// }); | ||
} | ||
return tree; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters