Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 935df713
authored
Dec 04, 2024
by
Netfan
Committed by
GitHub
Dec 04, 2024
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix: app config support `.env.local` (#5012)
1 parent
17c7ce8f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
5 deletions
internal/vite-config/src/utils/env.ts
internal/vite-config/src/utils/env.ts
View file @
935df71
import
type
{
ApplicationPluginOptions
}
from
'../typing'
;
import
type
{
ApplicationPluginOptions
}
from
'../typing'
;
import
{
existsSync
}
from
'node:fs'
;
import
{
join
}
from
'node:path'
;
import
{
join
}
from
'node:path'
;
import
{
fs
}
from
'@vben/node-utils'
;
import
{
fs
}
from
'@vben/node-utils'
;
...
@@ -21,12 +22,11 @@ function getConfFiles() {
...
@@ -21,12 +22,11 @@ function getConfFiles() {
const
script
=
process
.
env
.
npm_lifecycle_script
as
string
;
const
script
=
process
.
env
.
npm_lifecycle_script
as
string
;
const
reg
=
/--mode
([\d
_a-z
]
+
)
/
;
const
reg
=
/--mode
([\d
_a-z
]
+
)
/
;
const
result
=
reg
.
exec
(
script
);
const
result
=
reg
.
exec
(
script
);
let
mode
=
'production'
;
if
(
result
)
{
if
(
result
)
{
const
mode
=
result
[
1
];
mode
=
result
[
1
]
as
string
;
return
[
'.env'
,
`.env.
${
mode
}
`
];
}
}
return
[
'.env'
,
'.env.
production'
];
return
[
'.env'
,
'.env.
local'
,
`.env.
${
mode
}
`
,
`.env.
${
mode
}
.local`
];
}
}
/**
/**
...
@@ -42,11 +42,14 @@ async function loadEnv<T = Record<string, string>>(
...
@@ -42,11 +42,14 @@ async function loadEnv<T = Record<string, string>>(
for
(
const
confFile
of
confFiles
)
{
for
(
const
confFile
of
confFiles
)
{
try
{
try
{
const
envPath
=
await
fs
.
readFile
(
join
(
process
.
cwd
(),
confFile
),
{
const
confFilePath
=
join
(
process
.
cwd
(),
confFile
);
if
(
existsSync
(
confFilePath
))
{
const
envPath
=
await
fs
.
readFile
(
confFilePath
,
{
encoding
:
'utf8'
,
encoding
:
'utf8'
,
});
});
const
env
=
dotenv
.
parse
(
envPath
);
const
env
=
dotenv
.
parse
(
envPath
);
envConfig
=
{
...
envConfig
,
...
env
};
envConfig
=
{
...
envConfig
,
...
env
};
}
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
`Error while parsing
${
confFile
}
`
,
error
);
console
.
error
(
`Error while parsing
${
confFile
}
`
,
error
);
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment