Closed abdonrd closed 4 years ago
A simple temporary workaround from my side:
env.js
file in the root folder with this content:
const fs = require('fs');
const env = process.env['uenv'];
fs.writeFileSync('./environments/current.js', window.ENV = '${env}';
, 'utf8');
2. Create `/environments` folder with two files: `environments.js` and `current.js`. Place your environment configuration in the first one, like this:
export const ENV = { dev: { static: 'http://localhost:8081', api: 'http://localhost:3000' },
prod: {
static: 'http://prod:5000',
api: 'http://prod:3000'
}
};
3. Modify `scripts` section in your package.json:
... "scripts": { "start": "uenv=dev node ./env.js && polymer serve", "build:static": "uenv=dev node ./env.js && polymer build", ... }, ...
4. `import { ENV } from '../environments/environments';` to your component.
Now you're able to use env variables, e.g.: `ENV[window.ENV].api`.
This project is no longer under development and will be transitioning to a read-only repo. Thank you for your contributions.
Every project needs variables depending on the environment:
production
,staging
,development
, etc.For example, the URL of the API, the Analytics tracking ID, etc.