Home / Companies / Netlify / Blog / Post Details
Content Deep Dive

Access Local Environment Variables using Webpack

Blog post from Netlify

Post Details
Company
Date Published
Author
Brian Douglas
Word Count
365
Language
English
Hacker News Points
1
Summary

Netlify allows users to add environment variables to their builds, which can be defined through a user-friendly interface. However, this approach has the limitation that these variables cannot be accessed in local development environments. To overcome this, developers use a configuration file, such as `[environment_name].config.js`, to store sensitive information like secret keys. This file is then loaded using Webpack's `DefinePlugin` and allows for dynamic access to environment variables based on the current build configuration. Additionally, users can bypass the need for a separate Webpack config by passing variables directly through the `npm start` command, making it easier to test their site locally with different variables. By utilizing this approach, developers can ensure that their application behaves differently in development and production environments.