Skip to content

Explain the possible parameters when webpack.config.js exports a function #1479

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

Merged
merged 1 commit into from
Aug 7, 2017

Conversation

jennings
Copy link
Collaborator

@jennings jennings commented Aug 2, 2017

This adds a table of possible --env arguments and how they translate into the env parameter.

It also mentions the second parameter, argv, and gives an example of detecting if -p or --optimize-minimize was given.

Copy link
Collaborator

@skipjack skipjack left a comment

Choose a reason for hiding this comment

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

@jennings thanks for this addition. Please see my comment below, I think everything you've added is perfect, we should just move it to another section of the docs.

| webpack --env.prod=1 | { prod: 1 } |
| webpack --env.prod=foo | { prod: "foo" } |
| webpack --env.prod --env.bar | { prod: true, bar: true } |
| webpack --env.prod --env bar | [{ prod: true }, "bar"] |
Copy link
Collaborator

Choose a reason for hiding this comment

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

The majority of this should be moved to the CLI section of the documentation, probably in this section as that's the only place I'm seeing --env mentioned. Then, from this page, we should link to there (feel free to create a dedicated section for --env with a header so you can link directly to it's hash).

@jennings jennings force-pushed the config-function-params branch 2 times, most recently from d12cb4f to ccd2754 Compare August 6, 2017 06:20
@jennings
Copy link
Collaborator Author

jennings commented Aug 6, 2017

@skipjack Thanks for your help, I rebased and updated based on your suggestions, let me know if you'd like me to change anything else.

Copy link
Collaborator

@skipjack skipjack left a comment

Choose a reason for hiding this comment

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

@jennings added some other minor comments, once those are addressed we should be good to go.

@@ -129,6 +119,25 @@ webpack --json > stats.json

In every other case, webpack prints out a set of stats showing bundle, chunk and timing details. Using this option the output can be a JSON object. This response is accepted by webpack's [analyse tool](https://webpack.github.com/analyse), or chrisbateman's [webpack-visualizer](https://chrisbateman.github.io/webpack-visualizer/), or th0r's [webpack-bundle-analyzer](https://github.com/th0r/webpack-bundle-analyzer). The analyse tool will take in the JSON and provide all the details of the build in graphical form.

### Environment options
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would capitalize "Options" as it's in the title.

@@ -11,21 +11,26 @@ contributors:
Besides exporting a single config object, there are a few more ways that cover other needs as well.


## Exporting a function to use `--env`
## Exporting a function to use `--env` and `argv`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe simplify this title to "Exporting a Function"? Then in api/cli.md update your link to go directly here, e.g. /configuration/configuration-types#exporting-a-function.

One option is to export a function from your webpack config instead of exporting an object. The function will be invoked with two arguments:

* An environment as the first parameter. See the [environment options CLI documentation](/api/cli#environment-options) for syntax examples.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Drop this line break... typically between list items we don't include them.

* Expand on how --env arguments gets translated into the env parameter.

* Briefly explain the argv parameter.
@jennings jennings force-pushed the config-function-params branch from ccd2754 to 363650f Compare August 6, 2017 21:30
@jennings
Copy link
Collaborator Author

jennings commented Aug 6, 2017

@skipjack Updated:

  • Capitalized "Environment Options"
  • Removed the blank space between list items
  • Rename the title to "Exporting a Function" and fixed up the link
  • I also noticed I forgot to surround the environment examples with backticks, so I added those

@skipjack
Copy link
Collaborator

skipjack commented Aug 7, 2017

@jennings thanks! Awesome work on this as well as #1489. If you're interested in contributing regularly, I would be happy to invite you to the organization. I feel like we're finally getting this repo into a good place but there is still a little ways to go with the backlog before we can fully focus on cleaning things up, reviewing the content, and organizing it all properly.

Anyways any time you can spare is definitely appreciated.

@skipjack skipjack merged commit d4234bb into webpack:master Aug 7, 2017
@jennings jennings deleted the config-function-params branch August 7, 2017 17:43
@jennings
Copy link
Collaborator Author

jennings commented Aug 7, 2017

@skipjack Thanks :)

I do want to contribute more. I'm not certain yet how much time I can devote to it, but, I can give it a shot. Anything specific you would want me to go after? I saw #1258, it seems like most topics in your checklist have been "claimed".

I'm fairly new to webpack, but I don't mind learning something new in order to improve the docs.

@skipjack
Copy link
Collaborator

skipjack commented Aug 7, 2017

Yeah #1258 is pretty close to completion as you can see in this comment. The ones left are somewhat advanced so I don't know if that would be a good start.

If you could pick up any of the miscellaneous issues though that would be great and feel free to comment on them to discuss direction, e.g. where the new content might go if it's not obvious or just general thoughts on how the issue can be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants