This commit is contained in:
xiaoxiaojx 2025-10-03 21:38:11 +08:00
parent 3df51cb887
commit bbcf095dd9
4 changed files with 29 additions and 4 deletions

View File

@ -650,7 +650,7 @@
"additionalProperties": false,
"properties": {
"dir": {
"description": "The directory from which .env files are loaded. Defaults to the webpack context. Loads .env, .env.local, .env.[mode], .env.[mode].local in order.",
"description": "The directory from which .env files are loaded. Can be an absolute path, or a path relative to the project root. false will disable the .env file loading.",
"anyOf": [
{
"type": "boolean"

View File

@ -481,19 +481,19 @@ Object {
"dotenv-dir": Object {
"configs": Array [
Object {
"description": "The directory from which .env files are loaded. Defaults to the webpack context. Loads .env, .env.local, .env.[mode], .env.[mode].local in order.",
"description": "The directory from which .env files are loaded. Can be an absolute path, or a path relative to the project root. false will disable the .env file loading.",
"multiple": false,
"path": "dotenv.dir",
"type": "boolean",
},
Object {
"description": "The directory from which .env files are loaded. Defaults to the webpack context. Loads .env, .env.local, .env.[mode], .env.[mode].local in order.",
"description": "The directory from which .env files are loaded. Can be an absolute path, or a path relative to the project root. false will disable the .env file loading.",
"multiple": false,
"path": "dotenv.dir",
"type": "string",
},
],
"description": "The directory from which .env files are loaded. Defaults to the webpack context. Loads .env, .env.local, .env.[mode], .env.[mode].local in order.",
"description": "The directory from which .env files are loaded. Can be an absolute path, or a path relative to the project root. false will disable the .env file loading.",
"multiple": false,
"simpleType": "string",
},

View File

@ -0,0 +1,16 @@
"use strict";
it("should not load any .env files when dir is false", () => {
// When dir: false, no .env files should be loaded
// Only environment variables that were already set in process.env should be available
// and only those with WEBPACK_ prefix should be exposed
// These should be undefined since no .env files are loaded
expect(typeof process.env.WEBPACK_API_URL).toBe("undefined");
expect(typeof process.env.WEBPACK_MODE).toBe("undefined");
expect(typeof process.env.SECRET_KEY).toBe("undefined");
expect(typeof process.env.PRIVATE_VAR).toBe("undefined");
// Only pre-existing process.env variables with WEBPACK_ prefix should be available
// (if any were set before webpack runs)
});

View File

@ -41,5 +41,14 @@ module.exports = [
mode: "production",
entry: "./mode-specific.js",
dotenv: true
},
// Test 6: Disabled dir - dir: false disables .env file loading
{
name: "disabled-dir",
mode: "development",
entry: "./disabled-dir.js",
dotenv: {
dir: false
}
}
];