dotenv-webpack 7.1.0 → 8.0.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 +58 -13
- package/dist/index.js +8 -5
- package/package.json +2 -2
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`.
|
|
@@ -109,7 +109,7 @@ If you are running into issues where you or another package you use interfaces w
|
|
|
109
109
|
|
|
110
110
|
Use the following properties to configure your instance.
|
|
111
111
|
|
|
112
|
-
* **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).
|
|
113
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.
|
|
114
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).
|
|
115
115
|
* **systemvars** (`false`) - Set to true if you would rather load all system variables as well (useful for CI purposes).
|
|
@@ -138,6 +138,51 @@ module.exports = {
|
|
|
138
138
|
...
|
|
139
139
|
};
|
|
140
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',
|
|
151
|
+
})
|
|
152
|
+
]
|
|
153
|
+
...
|
|
154
|
+
};
|
|
155
|
+
```
|
|
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
|
+
```
|
|
141
186
|
|
|
142
187
|
## LICENSE
|
|
143
188
|
|
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) {
|
|
@@ -126,7 +126,7 @@ var Dotenv = /*#__PURE__*/function () {
|
|
|
126
126
|
var blueprint = env;
|
|
127
127
|
|
|
128
128
|
if (safe) {
|
|
129
|
-
var file =
|
|
129
|
+
var file = "".concat(path, ".example");
|
|
130
130
|
|
|
131
131
|
if (safe !== true) {
|
|
132
132
|
file = safe;
|
|
@@ -147,12 +147,13 @@ var Dotenv = /*#__PURE__*/function () {
|
|
|
147
147
|
key: "getDefaults",
|
|
148
148
|
value: function getDefaults() {
|
|
149
149
|
var _this$config3 = this.config,
|
|
150
|
+
path = _this$config3.path,
|
|
150
151
|
silent = _this$config3.silent,
|
|
151
152
|
defaults = _this$config3.defaults;
|
|
152
153
|
|
|
153
154
|
if (defaults) {
|
|
154
155
|
return this.loadFile({
|
|
155
|
-
file: defaults === true ?
|
|
156
|
+
file: defaults === true ? "".concat(path, ".defaults") : defaults,
|
|
156
157
|
silent: silent
|
|
157
158
|
});
|
|
158
159
|
}
|
|
@@ -219,8 +220,10 @@ var Dotenv = /*#__PURE__*/function () {
|
|
|
219
220
|
return targets.every(function (target) {
|
|
220
221
|
return (// If configured prefix is 'process.env'
|
|
221
222
|
_this.config.prefix === 'process.env.' && // If we're not configured to never stub
|
|
222
|
-
_this.config.ignoreStub !== true && ( //
|
|
223
|
-
|
|
223
|
+
_this.config.ignoreStub !== true && ( // And
|
|
224
|
+
// We are configured to always stub
|
|
225
|
+
_this.config.ignoreStub === false || // Or if we should according to the target
|
|
226
|
+
!target.includes('node') && !isMainThreadElectron(target))
|
|
224
227
|
);
|
|
225
228
|
});
|
|
226
229
|
}
|
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.1",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"precommit": "npm run lint",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@babel/register": "^7.13.8",
|
|
61
61
|
"husky": "^7.0.1",
|
|
62
62
|
"jest": "^27.0.4",
|
|
63
|
-
"jsdoc": "^3.6.
|
|
63
|
+
"jsdoc": "^3.6.10",
|
|
64
64
|
"rimraf": "^3.0.0",
|
|
65
65
|
"sinon": "^11.1.1",
|
|
66
66
|
"standard": "^16.0.3",
|