Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: expand description in readme #40

Merged
merged 5 commits into from
Mar 8, 2017
Merged

Conversation

j-feng13
Copy link

@j-feng13 j-feng13 commented Mar 7, 2017

@mrsteele
Here's a PR for #39

  1. Suggestions from @fakiolinho on explaining webpack.DefinePlugin being used under the hood
  2. Updated usage examples including your template
  3. Suggestions for a separate client .env file in order to prevent secrets from leaking into the client side bundle

@coveralls
Copy link

coveralls commented Mar 7, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 9d098df on j-feng13:update-docs into f989f68 on mrsteele:master.

Copy link
Owner

@mrsteele mrsteele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really awesome! just need a few changes and should be good to pull!

README.md Outdated
@@ -19,12 +19,31 @@ Include the package locally in your repository.

`npm install dotenv-webpack --save`

### Description

`dotenv-webpack` wraps `dotenv` and `Webpack.DefinePlugin`. As such, it overwrites existing anyexisting `DefinePlugin` configurations. Also, like `DefinePlugin`, it does a text replace in the resulting bundle for any instances of `process.env`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: anyexisting

README.md Outdated

`dotenv-webpack` wraps `dotenv` and `Webpack.DefinePlugin`. As such, it overwrites existing anyexisting `DefinePlugin` configurations. Also, like `DefinePlugin`, it does a text replace in the resulting bundle for any instances of `process.env`.

As such, if used with `React` in production, make sure to include `NODE_ENV=production` inside your `.env` file.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is a common use-case, I don't think you would need to mention React explicitly.

Instead I would mention something as follows:

Any script files that get bundled with webpack and reference process.env would need to use this plugin to access the variables defined in the .env file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrsteele I'm removing this text and adding an example

Use in your code
// file1.js
console.log(process.env.DB_HOST);
// '127.0.0.1'
Resulting bundle
// bundle.js
console.log({
	DB_HOST='127.0.0.1',
	DB_PASS='foobar',
	S3_API='mysecretkey'
}.DB_HOST);

README.md Outdated
`dotenv-webpack` wraps `dotenv` and `Webpack.DefinePlugin`. As such, it overwrites existing anyexisting `DefinePlugin` configurations. Also, like `DefinePlugin`, it does a text replace in the resulting bundle for any instances of `process.env`.

As such, if used with `React` in production, make sure to include `NODE_ENV=production` inside your `.env` file.
If used with Node, this is not compatible with any calls to `process.env`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Along with the comment above, I would say you can nix this comment as we are a webpack plugin and not exclusively a "node" plugin (though it runs in the node environment).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrsteele OK. I think adding an example of the resulting bundle should be clear enough.

README.md Outdated
As such, if used with `React` in production, make sure to include `NODE_ENV=production` inside your `.env` file.
If used with Node, this is not compatible with any calls to `process.env`.

Also, be aware that all information in your `.env` file will be included in the resulting bundle. Please do not share any secret information in your client bundle. Instead, make a separate `.client.env` file.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

README.md Outdated
@@ -33,14 +52,26 @@ module.exports = {
...
plugins: [
new Dotenv({
path: './.my.env', // if not simply .env
path: './.env // Path to .env file. Use a separate file for client configuration
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to close the path string.

@j-feng13
Copy link
Author

j-feng13 commented Mar 7, 2017

@mrsteele Thanks for the review. I'll get the changes in tonight.

@j-feng13
Copy link
Author

j-feng13 commented Mar 8, 2017

@mrsteele changes in. Let me know what you think.

@coveralls
Copy link

coveralls commented Mar 8, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling e4cae8e on j-feng13:update-docs into f989f68 on mrsteele:master.


`dotenv-webpack` wraps `dotenv` and `Webpack.DefinePlugin`. As such, it overwrites existing any existing `DefinePlugin` configurations. Also, like `DefinePlugin`, it does a text replace in the resulting bundle for any instances of `process.env`.

Also, be aware that all information in your `.env` file will be included in the resulting bundle. Please do not share any secret information in your client bundle. Instead, make a separate `.client.env` file.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed due to #42 so you can remove this paragraph. If you would rather we can simply state:

Your `.env` files can include sensative information. Because of this,`dotenv-webpack` will only include defined environment variables in the final bundle.

### Usage

The plugin can be installed with little-to-no configuration needed. Once installed, you can access the variables as expected within your code using `process.env`.
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`.

The example bellow shows the defaults, as well as a description of each parameter.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update the "defaults" statement as it isn't quite right.

###### Resulting bundle
```
// bundle.js
console.log({
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will update to the new approach (see #42)

@mrsteele
Copy link
Owner

mrsteele commented Mar 8, 2017

I'll merge this and make the final changes myself. Thank you so much for doing this @j-feng13!

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 4bf7274 on j-feng13:update-docs into eeb6a98 on mrsteele:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 4bf7274 on j-feng13:update-docs into eeb6a98 on mrsteele:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 4bf7274 on j-feng13:update-docs into eeb6a98 on mrsteele:master.

@coveralls
Copy link

coveralls commented Mar 8, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 4bf7274 on j-feng13:update-docs into eeb6a98 on mrsteele:master.

@mrsteele mrsteele merged commit 63a1343 into mrsteele:master Mar 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants