Skip to content

Commit

Permalink
Added envDir configuration options
Browse files Browse the repository at this point in the history
  • Loading branch information
ponjs committed Oct 8, 2022
1 parent 28421de commit d026aec
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ You can pass an `options` object to configure the plugin.
- _Default_: `{}`
- Custom additional environment variables. For more detailed env parsing rules, please refer to [the documentation of `dotenv`](https://github.com/motdotla/dotenv).

- `options.envDir`
- _Default_: `process.cwd()`
- The directory from which `.env` files are loaded. Can be an absolute path, or a path relative to the project root.

## Mode

You can specify env variables by placing the following files in your project root:
Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ function loadEnvironment(envPath) {
function overrideCracoConfig({ cracoConfig, pluginOptions = {} }) {
const mode = getModeName()

const basePath = path.resolve(process.cwd(), `.env${mode ? `.${mode}` : ''}`)
const envDirOption = pluginOptions.envDir
const resolvedRoot = process.cwd()

const basePath = path.resolve(
envDirOption ? path.resolve(resolvedRoot, envDirOption) : resolvedRoot,
`.env${mode ? `.${mode}` : ''}`
)
const localPath = `${basePath}.local`

loadEnvironment(localPath)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "craco-plugin-env",
"description": "An environment plugin for craco",
"version": "1.0.4",
"version": "1.0.5",
"main": "index.js",
"repository": "https://github.com/ponjs/craco-plugin-env.git",
"keywords": [
Expand Down

0 comments on commit d026aec

Please sign in to comment.