dotenv-webpack 6.0.0 → 6.0.4
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 +19 -17
- package/package.json +11 -13
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# dotenv-webpack
|
|
2
|
+
|
|
1
3
|
A secure webpack plugin that supports dotenv and other environment variables and **only exposes what you choose and use**.
|
|
2
4
|
|
|
3
5
|
<div align="center">
|
|
@@ -7,8 +9,8 @@ A secure webpack plugin that supports dotenv and other environment variables and
|
|
|
7
9
|
<a href="https://codecov.io/gh/mrsteele/dotenv-webpack" target="_blank">
|
|
8
10
|
<img alt="codecov" src="https://codecov.io/gh/mrsteele/dotenv-webpack/branch/master/graph/badge.svg" />
|
|
9
11
|
</a>
|
|
10
|
-
<a href="https://
|
|
11
|
-
<img alt="
|
|
12
|
+
<a href="https://github.com/mrsteele/dotenv-webpack/actions/workflows/main.yml" target="_blank">
|
|
13
|
+
<img alt="Main" src="https://github.com/mrsteele/dotenv-webpack/actions/workflows/main.yml/badge.svg" />
|
|
12
14
|
</a>
|
|
13
15
|
<a href="https://david-dm.org/mrsteele/dotenv-webpack" target="_blank">
|
|
14
16
|
<img alt="Dependency Status" src="https://david-dm.org/mrsteele/dotenv-webpack.svg" />
|
|
@@ -24,34 +26,34 @@ A secure webpack plugin that supports dotenv and other environment variables and
|
|
|
24
26
|
</h1>
|
|
25
27
|
</div>
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
## Installation
|
|
28
30
|
|
|
29
31
|
Include the package locally in your repository.
|
|
30
32
|
|
|
31
33
|
`npm install dotenv-webpack --save-dev`
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
## Description
|
|
34
36
|
|
|
35
37
|
`dotenv-webpack` wraps `dotenv` and `Webpack.DefinePlugin`. As such, it does a text replace in the resulting bundle for any instances of `process.env`.
|
|
36
38
|
|
|
37
39
|
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.
|
|
38
40
|
|
|
39
|
-
|
|
41
|
+
## Usage
|
|
40
42
|
|
|
41
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`.
|
|
42
44
|
|
|
43
45
|
The example bellow shows a standard use-case.
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
### Create a .env file
|
|
46
48
|
|
|
47
|
-
```
|
|
49
|
+
```dosini
|
|
48
50
|
// .env
|
|
49
51
|
DB_HOST=127.0.0.1
|
|
50
52
|
DB_PASS=foobar
|
|
51
53
|
S3_API=mysecretkey
|
|
52
54
|
|
|
53
55
|
```
|
|
54
|
-
|
|
56
|
+
### Add it to your Webpack config file
|
|
55
57
|
```javascript
|
|
56
58
|
// webpack.config.js
|
|
57
59
|
const Dotenv = require('dotenv-webpack');
|
|
@@ -65,7 +67,7 @@ module.exports = {
|
|
|
65
67
|
};
|
|
66
68
|
```
|
|
67
69
|
|
|
68
|
-
|
|
70
|
+
### Use in your code
|
|
69
71
|
|
|
70
72
|
```javascript
|
|
71
73
|
// file1.js
|
|
@@ -73,7 +75,7 @@ console.log(process.env.DB_HOST);
|
|
|
73
75
|
// '127.0.0.1'
|
|
74
76
|
```
|
|
75
77
|
|
|
76
|
-
|
|
78
|
+
### Resulting bundle
|
|
77
79
|
```javascript
|
|
78
80
|
// bundle.js
|
|
79
81
|
console.log('127.0.0.1');
|
|
@@ -81,19 +83,19 @@ console.log('127.0.0.1');
|
|
|
81
83
|
|
|
82
84
|
Note: the `.env` values for `DB_PASS` and `S3_API` are **NOT** present in our bundle, as they were never referenced (as `process.env.[VAR_NAME]`) in the code.
|
|
83
85
|
|
|
84
|
-
|
|
86
|
+
## How Secure?
|
|
85
87
|
|
|
86
88
|
By allowing you to define exactly where you are loading environment variables from and bundling only variables in your project that are explicitly referenced in your code, you can be sure that only what you need is included and you do not accidentally leak anything sensitive.
|
|
87
89
|
|
|
88
|
-
|
|
90
|
+
### Recommended
|
|
89
91
|
|
|
90
92
|
Add `.env` to your `.gitignore` file
|
|
91
93
|
|
|
92
|
-
|
|
94
|
+
## Limitations
|
|
93
95
|
|
|
94
|
-
Due to the fact that we use `webpack.DefinePlugin` under the hood, we cannot support destructing as that breaks how this plugin is meant to be used. Because of this, please reference your variables without destructing. For more information about this, please review the issue here
|
|
96
|
+
Due to the fact that we use `webpack.DefinePlugin` under the hood, we cannot support destructing as that breaks how this plugin is meant to be used. Because of this, please reference your variables without destructing. For more information about this, please review the issue [here](https://github.com/mrsteele/dotenv-webpack/issues/70).
|
|
95
97
|
|
|
96
|
-
|
|
98
|
+
## Properties
|
|
97
99
|
|
|
98
100
|
Use the following properties to configure your instance.
|
|
99
101
|
|
|
@@ -103,7 +105,7 @@ Use the following properties to configure your instance.
|
|
|
103
105
|
* **systemvars** (`false`) - Set to true if you would rather load all system variables as well (useful for CI purposes).
|
|
104
106
|
* **silent** (`false`) - If true, all warnings will be suppressed.
|
|
105
107
|
* **expand** (`false`) - Allows your variables to be "expanded" for reusability within your `.env` file.
|
|
106
|
-
* **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 https://www.npmjs.com/package/dotenv-defaults.
|
|
108
|
+
* **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).
|
|
107
109
|
|
|
108
110
|
The following example shows how to set any/all arguments.
|
|
109
111
|
|
|
@@ -124,6 +126,6 @@ module.exports = {
|
|
|
124
126
|
};
|
|
125
127
|
```
|
|
126
128
|
|
|
127
|
-
|
|
129
|
+
## LICENSE
|
|
128
130
|
|
|
129
131
|
MIT
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dotenv-webpack",
|
|
3
3
|
"description": "A simple webpack plugin to support dotenv.",
|
|
4
|
-
"version": "6.0.
|
|
4
|
+
"version": "6.0.4",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"precommit": "npm run lint",
|
|
8
8
|
"prepush": "npm t",
|
|
9
9
|
"lint": "standard",
|
|
10
10
|
"predoc": "rimraf docs",
|
|
11
|
-
"doc": "
|
|
11
|
+
"doc": "jsdoc src/index.js -d docs",
|
|
12
12
|
"pretest": "npm run build",
|
|
13
13
|
"test": "jest",
|
|
14
14
|
"prebuild": "rimraf dist",
|
|
@@ -48,19 +48,17 @@
|
|
|
48
48
|
"dotenv-defaults": "^2.0.1"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@babel/cli": "^7.
|
|
52
|
-
"@babel/core": "^7.
|
|
53
|
-
"@babel/preset-env": "^7.
|
|
54
|
-
"@babel/register": "^7.
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"husky": "^4.3.0",
|
|
59
|
-
"jest": "^25.0.0",
|
|
51
|
+
"@babel/cli": "^7.13.0",
|
|
52
|
+
"@babel/core": "^7.13.8",
|
|
53
|
+
"@babel/preset-env": "^7.13.9",
|
|
54
|
+
"@babel/register": "^7.13.8",
|
|
55
|
+
"husky": "^5.1.3",
|
|
56
|
+
"jest": "^25.5.4",
|
|
57
|
+
"jsdoc": "^3.6.6",
|
|
60
58
|
"rimraf": "^3.0.0",
|
|
61
59
|
"sinon": "^9.0.3",
|
|
62
|
-
"standard": "^16.0.
|
|
63
|
-
"webpack": "^5.3
|
|
60
|
+
"standard": "^16.0.3",
|
|
61
|
+
"webpack": "^5.24.3"
|
|
64
62
|
},
|
|
65
63
|
"files": [
|
|
66
64
|
"dist"
|