Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add built in .env support #4392

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Sakib25800
Copy link

@Sakib25800 Sakib25800 commented Feb 8, 2025

What kind of change does this PR introduce?
Feature:

  • .env file support following Vite's conventions
  • Only env variables prefixed with WEBPACK_ are exposed to Webpack-processed code
  • Env variables will also be available within webpack.config.js

Did you add tests for your changes?
Will add

If relevant, did you update the documentation?
Will add

Summary
Closes #3747

Does this PR introduce a breaking change?
No

Other information
This is my first PR, so there'll probably be a few mistakes / many questions

- Load env vars at build time and run time
Copy link

linux-foundation-easycla bot commented Feb 8, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.


const WebpackCLI = require("./webpack-cli");

const runCLI = async (args: Parameters<IWebpackCLI["run"]>[0]) => {
// Load environment variables from .env files
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that we want the env plugin to be default without any configuration. We should check if an env flag passed to the CLI/API is present.

Copy link
Author

@Sakib25800 Sakib25800 Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a --env-file flag for loading in variables from env files into webpack.config.js, but I've made the env plugin added by default so env vars can be accessed from bundled code without having to add the DotenvWebpackPlugin.

Is this what you meant?

Add support for import.meta.env and introduce --env-file flag to load
environment variables from .env files into the bundled files.

- Support for import.meta.env in webpack builds
- New --env-file CLI flag for specifying whether to load .env files for configuration
- Renamed dotenv plugin for clarity
- Add documentation for the dotenv webpack plugin
- Add --env-file flag to OPTIONS.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implement built-in .env support
2 participants