dotenv-webpack 7.0.2 → 7.1.1
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 +17 -15
- package/browser.js +1 -1
- package/dist/index.js +10 -5
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
<h1>
|
|
2
|
+
<img width="30" height="30" src="https://raw.githubusercontent.com/motdotla/dotenv/master/dotenv.png" alt="dotenv" />
|
|
3
|
+
<img width="30" height="30" src="https://webpack.js.org/assets/icon-square-big.svg" alt="webpack">
|
|
4
|
+
dotenv-webpack
|
|
5
|
+
</h1>
|
|
6
|
+
|
|
3
7
|
A secure webpack plugin that supports dotenv and other environment variables and **only exposes what you choose and use**.
|
|
4
8
|
|
|
5
9
|
<div align="center">
|
|
@@ -12,18 +16,10 @@ A secure webpack plugin that supports dotenv and other environment variables and
|
|
|
12
16
|
<a href="https://github.com/mrsteele/dotenv-webpack/actions/workflows/main.yml" target="_blank">
|
|
13
17
|
<img alt="Main" src="https://github.com/mrsteele/dotenv-webpack/actions/workflows/main.yml/badge.svg" />
|
|
14
18
|
</a>
|
|
15
|
-
<
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
<a href="https://david-dm.org/mrsteele/dotenv-webpack?type=dev" target="_blank">
|
|
19
|
-
<img alt="devDependency Status" src="https://david-dm.org/mrsteele/dotenv-webpack/dev-status.svg" />
|
|
19
|
+
<object id="badge" data="https://snyk-widget.herokuapp.com/badge/npm/dotenv-webpack/badge.svg" type="image/svg+xml"></object>
|
|
20
|
+
<a href="https://www.dotenv.org/get-started?r=3" target="_blank">
|
|
21
|
+
<img alt="dotenv-vault" src="https://badge.dotenv.org/works-with.svg?r=3" />
|
|
20
22
|
</a>
|
|
21
|
-
|
|
22
|
-
<h1>
|
|
23
|
-
<img width="30" height="30" src="https://raw.githubusercontent.com/motdotla/dotenv/master/dotenv.png" alt="dotenv" />
|
|
24
|
-
<img width="30" height="30" src="https://webpack.js.org/assets/icon-square-big.svg" alt="webpack">
|
|
25
|
-
dotenv-webpack
|
|
26
|
-
</h1>
|
|
27
23
|
</div>
|
|
28
24
|
|
|
29
25
|
## Installation
|
|
@@ -38,6 +34,8 @@ Include the package locally in your repository.
|
|
|
38
34
|
|
|
39
35
|
Your `.env` files can include sensitive information. Because of this,`dotenv-webpack` will only expose environment variables that are **explicitly referenced in your code** to your final bundle.
|
|
40
36
|
|
|
37
|
+
Interested in taking your environments to the next level? Check out the [Dotenv Organization](https://www.dotenv.org/get-started?r=3).
|
|
38
|
+
|
|
41
39
|
## Usage
|
|
42
40
|
|
|
43
41
|
The plugin can be installed with little-to-no configuration needed. Once installed, you can access the variables within your code using `process.env` as you would with `dotenv`.
|
|
@@ -101,7 +99,9 @@ Due to the fact that we use `webpack.DefinePlugin` under the hood, we cannot sup
|
|
|
101
99
|
|
|
102
100
|
We automatically replace any remaining `process.env`s in these environments with `"MISSING_ENV_VAR"` to avoid these errors.
|
|
103
101
|
|
|
104
|
-
|
|
102
|
+
When the `prefix` option is set, `process.env`s will not be stubbed.
|
|
103
|
+
|
|
104
|
+
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
105
|
|
|
106
106
|
## Properties
|
|
107
107
|
|
|
@@ -115,6 +115,7 @@ Use the following properties to configure your instance.
|
|
|
115
115
|
* **expand** (`false`) - Allows your variables to be "expanded" for reusability within your `.env` file.
|
|
116
116
|
* **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
117
|
* **ignoreStub** (`false`) - Override the automatic check whether to stub `process.env`. [Read more here](#user-content-processenv-stubbing--replacing).
|
|
118
|
+
* **prefix** (`'process.env.'`) - The prefix to use before the name of your env variables.
|
|
118
119
|
|
|
119
120
|
The following example shows how to set any/all arguments.
|
|
120
121
|
|
|
@@ -128,7 +129,8 @@ module.exports = {
|
|
|
128
129
|
allowEmptyValues: true, // allow empty variables (e.g. `FOO=`) (treat it as empty string, rather than missing)
|
|
129
130
|
systemvars: true, // load all the predefined 'process.env' variables which will trump anything local per dotenv specs.
|
|
130
131
|
silent: true, // hide any errors
|
|
131
|
-
defaults: false // load '.env.defaults' as the default values if empty.
|
|
132
|
+
defaults: false, // load '.env.defaults' as the default values if empty.
|
|
133
|
+
prefix: 'import.meta.env.' // reference your env variables as 'import.meta.env.ENV_VAR'.
|
|
132
134
|
})
|
|
133
135
|
]
|
|
134
136
|
...
|
package/browser.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
17
17
|
|
|
18
18
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
19
19
|
|
|
20
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
20
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
21
21
|
|
|
22
22
|
// Mostly taken from here: https://github.com/motdotla/dotenv-expand/blob/master/lib/main.js#L4
|
|
23
23
|
var interpolate = function interpolate(env, vars) {
|
|
@@ -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,7 +217,8 @@ 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
|
|
220
|
+
return (// If configured prefix is 'process.env'
|
|
221
|
+
_this.config.prefix === 'process.env.' && // If we're not configured to never stub
|
|
217
222
|
_this.config.ignoreStub !== true && ( // And
|
|
218
223
|
// We are configured to always stub
|
|
219
224
|
_this.config.ignoreStub === false || // Or if we should according to the target
|
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.
|
|
4
|
+
"version": "7.1.1",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"precommit": "npm run lint",
|
|
@@ -51,19 +51,18 @@
|
|
|
51
51
|
"webpack": "^4 || ^5"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"dotenv-defaults": "^2.0.
|
|
54
|
+
"dotenv-defaults": "^2.0.2"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@babel/cli": "^7.13.0",
|
|
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
|
-
"
|
|
64
|
-
"jsdoc": "^3.6.6",
|
|
61
|
+
"husky": "^7.0.1",
|
|
62
|
+
"jest": "^27.0.4",
|
|
63
|
+
"jsdoc": "^3.6.10",
|
|
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
|
},
|