Skip to content

Commit e66f387

Browse files
authored
Add Embroider compatibility note and recommendations (#121)
1 parent f227915 commit e66f387

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,56 @@ ember install ember-cli-dotenv
2323
* Move/convert the `dotEnv` application options from `ember-cli-build.js` to the function declared within `config/dotenv.js`
2424
* NOTE: if your `path` is dynamic see [Multiple Environments](https://github.com/fivetanley/ember-cli-dotenv#multiple-environments)
2525

26+
## Embroider Compatibility
27+
28+
This was addon was designed to work with classic Ember CLI build pipeline and
29+
approach used here simply does not work under Embroider.
30+
31+
For Ember apps using Embroider, it's recommended to use [`@embroider/macros`][macros]
32+
to pass Node.js environment variable(s) to Ember code. In `ember-cli-build.js`, do:
33+
34+
```javascript
35+
require('dotenv').config();
36+
37+
let app = new EmberApp(defaults, {
38+
'@embroider/macros': {
39+
// this is how you configure your own package
40+
setOwnConfig: {
41+
DROPBOX_KEY: process.env.DROPBOX_KEY
42+
},
43+
// this is how you can optionally send configuration into your
44+
// dependencies, if those dependencies choose to use
45+
// @embroider/macros configs.
46+
setConfig: {
47+
'some-dependency': {
48+
DROPBOX_KEY: process.env.DROPBOX_KEY
49+
},
50+
},
51+
},
52+
});
53+
```
54+
55+
In case if you need to consume env variable(s) only in FastBoot mode
56+
and ensure they don't get transferred to browser in `config/fastboot.js`, do:
57+
58+
```javascript
59+
require('dotenv').config();
60+
61+
module.exports = function(environment) {
62+
const myGlobal = {
63+
DROPBOX_KEY: process.env.DROPBOX_KEY,
64+
};
65+
66+
return {
67+
buildSandboxGlobals(defaultGlobals) {
68+
return Object.assign({}, defaultGlobals, {
69+
myGlobal,
70+
});
71+
},
72+
};
73+
}
74+
```
75+
2676
## What is Ember CLI Dotenv?
2777

2878
This addon allows you to write environment variables in a `.env` file and
@@ -180,3 +230,4 @@ See the [Contributing](CONTRIBUTING.md) guide for details.
180230
This project is licensed under the [MIT License](LICENSE.md).
181231

182232
[dotenv]: https://github.com/motdotla/dotenv
233+
[macros]: https://www.npmjs.com/package/@embroider/macros

0 commit comments

Comments
 (0)