-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): dot env support and template (#1580)
- Loading branch information
Showing
10 changed files
with
92 additions
and
1 deletion.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Environment variables | ||
|
||
This guide will help you to configure your shopware-pwa project using [environment variables](https://en.wikipedia.org/wiki/Environment_variable). | ||
|
||
## Usage | ||
|
||
Environment variables can be used within the application in many places, in the runtime as same as the build time. In nodejs-based application they can be accessed by using `process.env.[VARIABLE_CODE]`, `process.env.NODE_ENV` for instance. Nuxt and shopware-pwa itself uses some predefined variables to customize the application. | ||
|
||
The great example is a helper for getting images with optional image processor (treated like a proxy), the helper contains the piece of code: | ||
|
||
```js | ||
if (!process.env.EXPERIMENTAL_IMAGE_PROCESSING_SERVER) return originalImageSrc | ||
|
||
... | ||
|
||
let url = `${process.env.EXPERIMENTAL_IMAGE_PROCESSING_SERVER}?url=${mediaUrl}` | ||
|
||
``` | ||
|
||
Shopware-pwa provides the optional way of setting env variables by using `.env` file, instead of setting them up using system environment variables explicitly like: | ||
|
||
`EXPERIMENTAL_IMAGE_PROCESSING_SERVER=https://someserver.com/img/ shopware-pwa dev` or even before running the nodejs process, manually. | ||
|
||
|
||
## Setup | ||
|
||
A generated project contains `.env.template` among other files placed in root directory. | ||
|
||
::: tip | ||
Remember that the `.env` file is listed in `.gitignore` and shouldn't be versioned because it may contain some sensitive data. | ||
::: | ||
|
||
|
||
The `.env.template` file's content may look similar to this one: | ||
|
||
``` | ||
HOST=0.0.0.0 | ||
PORT=3000 | ||
ADMIN_USER=admin | ||
ADMIN_PASSWORD=shopware | ||
ENABLE_DEVTOOLS=false | ||
NODE_ENV=production | ||
EXPERIMENTAL_IMAGE_PROCESSING_SERVER | ||
``` | ||
|
||
**In order to activate the variables from the file, change the template's name to just `.env`** | ||
|
||
## Description | ||
|
||
The default environment variables | ||
|
||
- `HOST` - nuxt server host name (`0.0.0.0` by default) | ||
- `PORT` - nuxt server port number (`3000` by default) | ||
- `ADMIN_USER` - Shopware 6 admin user name (`admin` by default) | ||
- `ADMIN_PASSWORD` - Shopware 6 admin password (`shopware` by default) | ||
- `ENABLE_DEVTOOLS` - config turning on the nuxt dev tools (`true` by default) | ||
- `NODE_ENV` - application mode: dev or production (`dev` by default) | ||
- `EXPERIMENTAL_IMAGE_PROCESSING_SERVER` - URL to the custom image processor (well described [here](https://github.com/vuestorefront/shopware-pwa/blob/master/packages/default-theme/src/helpers/images/getResizedImage.js)) | ||
|
||
::: tip | ||
shopware-pwa CLI tool can also detect the current state of environment variables and use given `ADMIN_USER` and `ADMIN_PASSWORD` values in `plugins` and `domains` commands (suggest credentials). | ||
|
||
![cli](./../../assets/env_cli.png) | ||
::: |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/usr/bin/env node | ||
|
||
require('dotenv').config() | ||
|
||
/* tslint:disable */ | ||
// check if we're running in dev mode | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
HOST=0.0.0.0 | ||
PORT=3000 | ||
ADMIN_USER=admin | ||
ADMIN_PASSWORD=shopware | ||
ENABLE_DEVTOOLS=true | ||
NODE_ENV=dev | ||
EXPERIMENTAL_IMAGE_PROCESSING_SERVER |
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
aa44c77
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: