dotenv-webpack 7.0.3 → 8.0.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 +63 -14
- package/browser.js +1 -1
- package/dist/index.js +13 -7
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
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>
|
|
2
6
|
|
|
3
7
|
A secure webpack plugin that supports dotenv and other environment variables and **only exposes what you choose and use**.
|
|
4
8
|
|
|
@@ -12,18 +16,12 @@ 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
|
-
|
|
19
|
+
<img alt="Vulnerabilities Score" src="https://snyk-widget.herokuapp.com/badge/npm/dotenv-webpack/badge.svg" />
|
|
20
|
+
<img alt="Known Vulnerabilities" src="https://snyk.io/test/github/mrsteele/dotenv-webpack/badge.svg" />
|
|
21
|
+
<object id="badge" data="https://snyk-widget.herokuapp.com/badge/npm/dotenv-webpack/badge.svg" type="image/svg+xml"></object>
|
|
22
|
+
<a href="https://www.dotenv.org/get-started?r=3" target="_blank">
|
|
23
|
+
<img alt="dotenv-vault" src="https://badge.dotenv.org/works-with.svg?r=3" />
|
|
17
24
|
</a>
|
|
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" />
|
|
20
|
-
</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
25
|
</div>
|
|
28
26
|
|
|
29
27
|
## Installation
|
|
@@ -38,6 +36,8 @@ Include the package locally in your repository.
|
|
|
38
36
|
|
|
39
37
|
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
38
|
|
|
39
|
+
Interested in taking your environments to the next level? Check out the [Dotenv Organization](https://www.dotenv.org/get-started?r=3).
|
|
40
|
+
|
|
41
41
|
## Usage
|
|
42
42
|
|
|
43
43
|
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,13 +101,15 @@ 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
|
|
107
109
|
|
|
108
110
|
Use the following properties to configure your instance.
|
|
109
111
|
|
|
110
|
-
* **path** (`'./.env'`) - The path to your environment variables.
|
|
112
|
+
* **path** (`'./.env'`) - The path to your environment variables. This same path applies to the `.env.example` and `.env.defaults` files. [Read more here](#about-path-settings).
|
|
111
113
|
* **safe** (`false`) - If true, load '.env.example' to verify the '.env' variables are all set. Can also be a string to a different file.
|
|
112
114
|
* **allowEmptyValues** (`false`) - Whether to allow empty strings in safe mode. If false, will throw an error if any env variables are empty (but only if safe mode is enabled).
|
|
113
115
|
* **systemvars** (`false`) - Set to true if you would rather load all system variables as well (useful for CI purposes).
|
|
@@ -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,13 +131,59 @@ 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'.
|
|
136
|
+
})
|
|
137
|
+
]
|
|
138
|
+
...
|
|
139
|
+
};
|
|
140
|
+
```
|
|
141
|
+
## About `path` settings
|
|
142
|
+
|
|
143
|
+
As previously mentioned, it is possible to customize the `path` where the `.env` file is located as well as its *filename* from the plugin settings:
|
|
144
|
+
|
|
145
|
+
```javascript
|
|
146
|
+
module.exports = {
|
|
147
|
+
...
|
|
148
|
+
plugins: [
|
|
149
|
+
new Dotenv({
|
|
150
|
+
path: './some.other.env',
|
|
132
151
|
})
|
|
133
152
|
]
|
|
134
153
|
...
|
|
135
154
|
};
|
|
136
155
|
```
|
|
137
156
|
|
|
157
|
+
It is important to mention that this same path and filename will be used for the location of the `.env.example` and `.env.defaults` files if they are configured, this will only add the `.example` and `.defaults` suffixes respectively:
|
|
158
|
+
|
|
159
|
+
```javascript
|
|
160
|
+
module.exports = {
|
|
161
|
+
...
|
|
162
|
+
plugins: [
|
|
163
|
+
new Dotenv({
|
|
164
|
+
path: '../../path/to/other.env',
|
|
165
|
+
safe: true, // load '../../path/to/other.env.example'
|
|
166
|
+
defaults: true, // load '../../path/to/other.env.defaults'
|
|
167
|
+
})
|
|
168
|
+
]
|
|
169
|
+
...
|
|
170
|
+
};
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
This is especially useful when working with [Monorepos](https://monorepo.tools/) where the same configuration can be shared within all sub-packages of the repository:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
.
|
|
177
|
+
├── packages/
|
|
178
|
+
│ ├── app/
|
|
179
|
+
│ │ └── webpack.config.js # { path: '../../.env' }
|
|
180
|
+
│ └── libs/
|
|
181
|
+
│ └── webpack.config.js # { path: '../../.env' }
|
|
182
|
+
├── .env
|
|
183
|
+
├── .env.example
|
|
184
|
+
└── .env.defaults
|
|
185
|
+
```
|
|
186
|
+
|
|
138
187
|
## LICENSE
|
|
139
188
|
|
|
140
189
|
MIT
|
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
|
|
|
@@ -124,7 +126,7 @@ var Dotenv = /*#__PURE__*/function () {
|
|
|
124
126
|
var blueprint = env;
|
|
125
127
|
|
|
126
128
|
if (safe) {
|
|
127
|
-
var file =
|
|
129
|
+
var file = "".concat(path, ".example");
|
|
128
130
|
|
|
129
131
|
if (safe !== true) {
|
|
130
132
|
file = safe;
|
|
@@ -145,12 +147,13 @@ var Dotenv = /*#__PURE__*/function () {
|
|
|
145
147
|
key: "getDefaults",
|
|
146
148
|
value: function getDefaults() {
|
|
147
149
|
var _this$config3 = this.config,
|
|
150
|
+
path = _this$config3.path,
|
|
148
151
|
silent = _this$config3.silent,
|
|
149
152
|
defaults = _this$config3.defaults;
|
|
150
153
|
|
|
151
154
|
if (defaults) {
|
|
152
155
|
return this.loadFile({
|
|
153
|
-
file: defaults === true ?
|
|
156
|
+
file: defaults === true ? "".concat(path, ".defaults") : defaults,
|
|
154
157
|
silent: silent
|
|
155
158
|
});
|
|
156
159
|
}
|
|
@@ -164,10 +167,12 @@ var Dotenv = /*#__PURE__*/function () {
|
|
|
164
167
|
variables = _ref$variables === void 0 ? {} : _ref$variables,
|
|
165
168
|
target = _ref.target,
|
|
166
169
|
version = _ref.version;
|
|
167
|
-
var
|
|
170
|
+
var _this$config4 = this.config,
|
|
171
|
+
expand = _this$config4.expand,
|
|
172
|
+
prefix = _this$config4.prefix;
|
|
168
173
|
var formatted = Object.keys(variables).reduce(function (obj, key) {
|
|
169
174
|
var v = variables[key];
|
|
170
|
-
var vKey = "
|
|
175
|
+
var vKey = "".concat(prefix).concat(key);
|
|
171
176
|
var vValue;
|
|
172
177
|
|
|
173
178
|
if (expand) {
|
|
@@ -213,7 +218,8 @@ var Dotenv = /*#__PURE__*/function () {
|
|
|
213
218
|
|
|
214
219
|
var targets = Array.isArray(targetInput) ? targetInput : [targetInput];
|
|
215
220
|
return targets.every(function (target) {
|
|
216
|
-
return (// If
|
|
221
|
+
return (// If configured prefix is 'process.env'
|
|
222
|
+
_this.config.prefix === 'process.env.' && // If we're not configured to never stub
|
|
217
223
|
_this.config.ignoreStub !== true && ( // And
|
|
218
224
|
// We are configured to always stub
|
|
219
225
|
_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": "
|
|
4
|
+
"version": "8.0.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
|
-
"
|
|
64
|
-
"jsdoc": "^3.6.7",
|
|
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
|
},
|