-
Notifications
You must be signed in to change notification settings - Fork 31
Import config/environment in application #89
Comments
@topaxi What are you trying to do? Define your own module config? |
I want a way to define global configuration variables like API endpoints or production / development URLs, disabling Logging in production etc. I've done these things in Ember.js with the |
I'm curious about this too |
I also was wondering about the correct way to go about this. I have tried looking this up and the methods used in a standard ember-cli application do not work. Here is the scenario I think which is same that @topaxi is going for. Setting up an ENV variable inside the // app/config/environment.js
'use strict';
module.exports = function(environment) {
let ENV = {
modulePrefix: 'foo-app',
environment: environment,
};
ENV.token = process.env['API_TOKEN']
return ENV;
}; Then wanting to take said ENV variable inside a component inside your app. Normally (in ember-cli) you would simply import your config file via // app/src/ui/components/foo-component/component.js
import Component, { tracked } from '@glimmer/component';
import ENV from 'config/environemt'
export default class FooComponent extends Component {
...
fooBarToken = ENV.token
...
}; The error thrown has to do with unable to resolve the path
Adjusting the path to a relative path that points directly to the file throws errors because it is trying to import the node module as an es6 module // app/src/ui/components/foo-component/component.js
import ENV from '../../../../config/environment'
export default class FooComponent extends Component {
}; throws
I am sure there is probably a way about grabbing these ENV variables without too many band-aids and would appreciate any help on how to go about this as well. |
What happens if you enable commonJS module imports as the readme.md for this project says? |
I'm also interested in this issue. Does anyone have a working solution? UPDATE: I created a plugin which tries to include the |
I'm not seeing the config/environment.js in the broccoli tree. there is an environment subdirectory with a development.js in it. |
We should absolutely fix this. It shouldn't be too much work to fix I think... |
I am using rollup-replace-plugin.
Then using |
as requested by @hoodwink73 on the glimmer slack channel, I created a repo with my hack. You can find it here: https://github.com/tschoartschi/glimmer-env-hack But it's really a hack. For detailed explanations check the README.md of the repo |
@rwjblue there are several "solutions", "suggestions" and "hacks" to this problem. What should be the common approach to use the |
Just wanted to leave a bit from my experiments. It looks like importing is working through some configuration changes.
If this is "official" then I think we could close this, and I could open a PR up for the Glimmer guides. Hope this at least helps the next person to come along. Cheers! |
…nvironment bug config/environment.js could be used for building (via meta tag) but not for tests. See: glimmerjs/glimmer-application-pipeline#89 Once this is fixed application environment configuration can be consolidated in one spot.
Even though there are other solutions in this thread, importing |
Is there a way to import
config/environment.js
in a glimmer application? I haven't found a way yet.The text was updated successfully, but these errors were encountered: