Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion docs/v3.x/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,23 @@ build: {
extend: () => {} // can be used to modify webpack config
}
```
---
If you want to load env files to your code depend on the environment, you could take advantage of the extend config here. Under `build.extend`, you can add your own plugins by doing something like this
```
extend: {
plugins: [
new webpack.DefinePlugin({
'process.env': JSON.stringify(envVars)
})
]
}
```
You can grab the envVars dynamically from the file depends on the `NODE_ENV`. For example, if you are using dotenv package:
```
const nodeEnv = process.env.NODE_ENV || 'development';
const dotenv = require('dotenv')
const envVars = dotenv.parse(fs.readFileSync(`.env.${env}`));
```

---
## devServer
Expand Down Expand Up @@ -268,4 +285,4 @@ unitTesting: {
]
}
```
*Note - these settings correspond to v3.5+ refer to <a href="/aofl/#/v2.x/getting-started/configuration?id=unittesting" rel="noopener noreferrer">v2</a> documentation for earlier versions*
*Note - these settings correspond to v3.5+ refer to <a href="/aofl/#/v2.x/getting-started/configuration?id=unittesting" rel="noopener noreferrer">v2</a> documentation for earlier versions*