dotenv-webpack 7.0.0 → 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 CHANGED
@@ -101,7 +101,9 @@ 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
- If you are running into issues where you or another package you use interfaces with `process.env`, it might be best to set `ignoreStubs: 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).
104
+ When the `prefix` option is set, `process.env`s will not be stubbed.
105
+
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
 
@@ -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
@@ -1,3 +1,3 @@
1
- var plugin = require('./dist').default
1
+ const plugin = require('./dist').default
2
2
 
3
3
  module.exports = plugin
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
 
@@ -62,7 +64,7 @@ var Dotenv = /*#__PURE__*/function () {
62
64
 
63
65
  var variables = this.gatherVariables();
64
66
  var target = (_compiler$options$tar = compiler.options.target) !== null && _compiler$options$tar !== void 0 ? _compiler$options$tar : 'web';
65
- var version = compiler.webpack.version;
67
+ var version = compiler.webpack && compiler.webpack.version || '4';
66
68
  var data = this.formatData({
67
69
  variables: variables,
68
70
  target: target,
@@ -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 expand = this.config.expand;
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 = "process.env.".concat(key);
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 we're not configured to never stub
217
- _this.config.ignoreStub !== true && ( // And
218
- // We are configured to always stub
219
- _this.config.ignoreStub === false || // Or if we should according to the target
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.0",
4
+ "version": "7.1.0",
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.1"
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
- "fs-extra": "^9.1.0",
62
- "husky": "^5.1.3",
63
- "jest": "^25.5.4",
64
- "jsdoc": "^3.6.6",
61
+ "husky": "^7.0.1",
62
+ "jest": "^27.0.4",
63
+ "jsdoc": "^3.6.7",
65
64
  "rimraf": "^3.0.0",
66
- "sinon": "^9.0.3",
65
+ "sinon": "^11.1.1",
67
66
  "standard": "^16.0.3",
68
67
  "webpack": "^5.24.3"
69
68
  },