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

Overwriting config parameters through CLI #155

Closed
webpack-bot opened this issue May 19, 2017 · 5 comments
Closed

Overwriting config parameters through CLI #155

webpack-bot opened this issue May 19, 2017 · 5 comments

Comments

@webpack-bot
Copy link

Do you want to request a feature or report a bug?

feature

What is the current behavior?

According to my understanding and tests, I can use webpack either in combination with a config file which includes the entry and output paths, or I can pass the entry and output path as CLI arguments. But both alternatives are mutually exclusive, i.e. I cannot overwrite the entry and output paths specified in a config file through CLI parameters, while still using the other specifications in the config file.

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?

I want to use a webpack.config.js AND overwrite the entry and output paths of that config file using CLI parameters.

If this is a feature request, what is motivation or use case for changing the behavior?

I need to change entry and output paths dynamically and depending on some context while keeping the other entries of an entry file.

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.


This issue was moved from webpack/webpack#4895 by @bebraw. Orginal issue was by @fera0013.

@kristoforsalmin
Copy link

Hi,

That's a great idea! I don't know if that would be helpful, but PostCSS CLI handles this in a nice manner. They have a ctx object passed into your config that contains all processed CLI options.

https://github.com/postcss/postcss-cli/blob/master/index.js#L126 and then in your config you can:

module.exports = ({ options }) => ({
  map: options.map,
  ...
});

It actually would be great if that would be possible with the webpack CLI as well. I often need dynamically set context, path or publicPath. For example if I were to run webpack src/scripts/main.js -o dist/scripts/[name].bundle.js, then I'd be awesome to have something like this:

const path = require('path');

module.exports = ({ options }) => ({
  output: {
    publicPath: `/${options.outputPath.split(path.sep).pop()}/`
  }
  ...
});

Thanks! 😄

@bitpshr
Copy link
Member

bitpshr commented Mar 18, 2018

The example usage printed by the CLI is a bit misleading:

Usage without config file: webpack <entry> [<entry>] --output [-o] <output>
Usage with config file: webpack

The current implementation always tries to find a configuration file, using either a list of default names (e.g. webpack.config.js) or using the path specified for the --config CLI option. Regardless of whether a configuration file is actually specified or found, new entry points can always be dynamically added using the webpack <entry> or webpack --entry syntax, and the output can always be dynamically modified using the --output CLI option.

The issue I see with the current implementation is that new entry points are always appended when using webpack <entry> or webpack --entry syntax, even when a configuration file is found. This sort of makes the OP's original end goal more difficult (if not impossible), to override entry and output specified in a configuration file via CLI arguments. It's currently possible to override output but only possible to append to entry.

I propose that any entry points specified via CLI options override any entry configuration specified in a configuration file rather than appending to it. Thoughts? @ev1stensberg @ematipico @dhruvdutt

@evenstensberg
Copy link
Member

Send a PR

@bitpshr
Copy link
Member

bitpshr commented Mar 20, 2018

@ev1stensberg see #358.

@evenstensberg
Copy link
Member

Closed via #358

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

No branches or pull requests

4 participants