dotenv-webpack 7.0.3 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/browser.js +1 -1
- package/dist/index.js +11 -8
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -101,6 +101,8 @@ Due to the fact that we use `webpack.DefinePlugin` under the hood, we cannot sup
|
|
|
101
101
|
|
|
102
102
|
We automatically replace any remaining `process.env`s in these environments with `"MISSING_ENV_VAR"` to avoid these errors.
|
|
103
103
|
|
|
104
|
+
When the `prefix` option is set, `process.env`s will not be stubbed.
|
|
105
|
+
|
|
104
106
|
If you are running into issues where you or another package you use interfaces with `process.env`, it might be best to set `ignoreStub: true` and make sure you always reference variables that exist within your code (See [this issue](https://github.com/mrsteele/dotenv-webpack/issues/271) for more information).
|
|
105
107
|
|
|
106
108
|
## Properties
|
|
@@ -115,6 +117,7 @@ Use the following properties to configure your instance.
|
|
|
115
117
|
* **expand** (`false`) - Allows your variables to be "expanded" for reusability within your `.env` file.
|
|
116
118
|
* **defaults** (`false`) - Adds support for `dotenv-defaults`. If set to `true`, uses `./.env.defaults`. If a string, uses that location for a defaults file. Read more at [npm](https://www.npmjs.com/package/dotenv-defaults).
|
|
117
119
|
* **ignoreStub** (`false`) - Override the automatic check whether to stub `process.env`. [Read more here](#user-content-processenv-stubbing--replacing).
|
|
120
|
+
* **prefix** (`'process.env.'`) - The prefix to use before the name of your env variables.
|
|
118
121
|
|
|
119
122
|
The following example shows how to set any/all arguments.
|
|
120
123
|
|
|
@@ -128,7 +131,8 @@ module.exports = {
|
|
|
128
131
|
allowEmptyValues: true, // allow empty variables (e.g. `FOO=`) (treat it as empty string, rather than missing)
|
|
129
132
|
systemvars: true, // load all the predefined 'process.env' variables which will trump anything local per dotenv specs.
|
|
130
133
|
silent: true, // hide any errors
|
|
131
|
-
defaults: false // load '.env.defaults' as the default values if empty.
|
|
134
|
+
defaults: false, // load '.env.defaults' as the default values if empty.
|
|
135
|
+
prefix: 'import.meta.env.' // reference your env variables as 'import.meta.env.ENV_VAR'.
|
|
132
136
|
})
|
|
133
137
|
]
|
|
134
138
|
...
|
package/browser.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -43,6 +43,7 @@ var Dotenv = /*#__PURE__*/function () {
|
|
|
43
43
|
* @param {Boolean|String} [options.safe=false] - If false ignore safe-mode, if true load `'./.env.example'`, if a string load that file as the sample.
|
|
44
44
|
* @param {Boolean} [options.systemvars=false] - If true, load system environment variables.
|
|
45
45
|
* @param {Boolean} [options.silent=false] - If true, suppress warnings, if false, display warnings.
|
|
46
|
+
* @param {String} [options.prefix=process.env.] - The prefix, used to denote environment variables.
|
|
46
47
|
* @returns {webpack.DefinePlugin}
|
|
47
48
|
*/
|
|
48
49
|
function Dotenv() {
|
|
@@ -51,7 +52,8 @@ var Dotenv = /*#__PURE__*/function () {
|
|
|
51
52
|
_classCallCheck(this, Dotenv);
|
|
52
53
|
|
|
53
54
|
this.config = Object.assign({}, {
|
|
54
|
-
path: './.env'
|
|
55
|
+
path: './.env',
|
|
56
|
+
prefix: 'process.env.'
|
|
55
57
|
}, config);
|
|
56
58
|
}
|
|
57
59
|
|
|
@@ -164,10 +166,12 @@ var Dotenv = /*#__PURE__*/function () {
|
|
|
164
166
|
variables = _ref$variables === void 0 ? {} : _ref$variables,
|
|
165
167
|
target = _ref.target,
|
|
166
168
|
version = _ref.version;
|
|
167
|
-
var
|
|
169
|
+
var _this$config4 = this.config,
|
|
170
|
+
expand = _this$config4.expand,
|
|
171
|
+
prefix = _this$config4.prefix;
|
|
168
172
|
var formatted = Object.keys(variables).reduce(function (obj, key) {
|
|
169
173
|
var v = variables[key];
|
|
170
|
-
var vKey = "
|
|
174
|
+
var vKey = "".concat(prefix).concat(key);
|
|
171
175
|
var vValue;
|
|
172
176
|
|
|
173
177
|
if (expand) {
|
|
@@ -213,11 +217,10 @@ var Dotenv = /*#__PURE__*/function () {
|
|
|
213
217
|
|
|
214
218
|
var targets = Array.isArray(targetInput) ? targetInput : [targetInput];
|
|
215
219
|
return targets.every(function (target) {
|
|
216
|
-
return (// If
|
|
217
|
-
_this.config.
|
|
218
|
-
// We are configured to always stub
|
|
219
|
-
_this.config.ignoreStub === false ||
|
|
220
|
-
!target.includes('node') && !isMainThreadElectron(target))
|
|
220
|
+
return (// If configured prefix is 'process.env'
|
|
221
|
+
_this.config.prefix === 'process.env.' && // If we're not configured to never stub
|
|
222
|
+
_this.config.ignoreStub !== true && ( // We are configured to always stub
|
|
223
|
+
_this.config.ignoreStub === false || !target.includes('node') && !isMainThreadElectron(target))
|
|
221
224
|
);
|
|
222
225
|
});
|
|
223
226
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dotenv-webpack",
|
|
3
3
|
"description": "A simple webpack plugin to support dotenv.",
|
|
4
|
-
"version": "7.0
|
|
4
|
+
"version": "7.1.0",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"precommit": "npm run lint",
|
|
@@ -58,12 +58,11 @@
|
|
|
58
58
|
"@babel/core": "^7.13.8",
|
|
59
59
|
"@babel/preset-env": "^7.13.9",
|
|
60
60
|
"@babel/register": "^7.13.8",
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"jest": "^26.6.3",
|
|
61
|
+
"husky": "^7.0.1",
|
|
62
|
+
"jest": "^27.0.4",
|
|
64
63
|
"jsdoc": "^3.6.7",
|
|
65
64
|
"rimraf": "^3.0.0",
|
|
66
|
-
"sinon": "^
|
|
65
|
+
"sinon": "^11.1.1",
|
|
67
66
|
"standard": "^16.0.3",
|
|
68
67
|
"webpack": "^5.24.3"
|
|
69
68
|
},
|