Webpack-cli: Add --no-config arg option to ignore webpack.config.js

Created on 6 Apr 2017  路  17Comments  路  Source: webpack/webpack-cli

What is the current behavior?
The only way to run webpack with no config file is to not have a config file in the working directory

What is the expected behavior?
I should have a --no-config (or similar) option that can tell webpack to ignore the config file that's sitting in our directory.

If this is a feature request, what is motivation or use case for changing the behavior?
I have a big project that uses a webpack.config.js for our main app but I want to also build a helper app for devs via npm script, perhaps webpack --no-config --module-bind js=babel-loader input.js output.js

P.S. I'm willing to make a PR for this if it's considered a good idea!

Discussion Feature Request Good First Contribution question

Most helpful comment

It took me one day (= trial and error) to realize that I cannot ignore webpack.config.js file
I cannot remember any Unix Tools with which when we do not want a config file the CLI still uses it :(
I developed some CLIs in C and C++ for Linux and I am really surprised about webpack-cli behavior:

  1. It is run even with non existing option
    ./node_module/.bin/webpack-cli --xxxxxxxx

  2. It is run with wrong option
    ./node_module/.bin/webpack-cli --output-target--library # correct: --output-library-target

  3. It reads config file even when --config parameter is [ false | null | "" ]

./node_modules/.bin/webpack \
> --config "" \
> --entry ./test/es6/main.js \
> --output ./test/es6/main.bundle.js \
> --module-bind js=babel-loader \
> --mode development

More surprisingly there is a --no-color option that works while the --no-config has the real usability

20190418_134421

All 17 comments

Can't you just supply with webpack ../../i.js ../../o.js?

Actually no - if a config exists it is used automatically when none is specified. https://github.com/webpack/webpack-cli/blob/master/bin/convert-argv.js#L62

Hm, troublesome. I'll ask around to see if there's a workaround for this. I'll notify you if we can accept a PR. Thanks for the heads-up @benwiley4000 !

There's a workaround for this. You can rename your configuration, and require it through --config.

Certainly true, though I think I shouldn't be required to rename the config file in order to achieve this behavior. If a number of npm scripts implicitly use the default config, and I want to add only one which uses no configuration, it's a simpler change to be able to override default behavior in that one case.

Yeah I can see that. Open a PR, I'll bring it up for discussion, it's not 100% it's gonna be merged though.

Could you not just move the webpack.config.js into a e.g .config/config folder and set it explicitly ?

So basically the other way around

Closing for now due inactivity, @benwiley4000 if you're unhappy with this I can reopen or @michael-ciniawsky could elaborate on the issue your facing. Assuming this is resolved.

Sorry for being stagnant. I'll try a PR soon if I can find the time.

Awesome! We're releasing the new CLI today or tomorrow, might be good to wait until then to start with that. Furthermore, we can't guarantee this being merged. If you can provide some insight with more context around why this is good to the average user , there's more chances to this being merged.

If you need help with the PR, lemme know!

Cheers!

Sorry I still haven't had time to work on this. As for why this is useful... I can't at the moment remember what I was trying to do, but I think it was something along the lines of trying to quickly test some settings that weren't in my config. It's annoying to have to manually override every single config file setting with a flag. Ideally I shouldn't have to rename files and clutter up my staged files in git.

I think Michael touched on some workarounds, a detailed user story with a repository and such, as I've mentioned earlier would be great if we were to prioritize this. 鉁岋笍

I had a need for this in a library where I wanted to bundle some modules together for node with Webpack, leveraging it's inlining of required modules with a goal of optimizing the package size. I could have used npmignore but creating a bundle index was easier.

My config file does a bunch of other undesirable things for this purpose, and is already shared with other projects, so can't easily rename. To workaround I made a webpack.noop.js config file that exports an empty object and I use that with the CLI.

Maybe this could function well with our 0CJS story @sokra.

It took me one day (= trial and error) to realize that I cannot ignore webpack.config.js file
I cannot remember any Unix Tools with which when we do not want a config file the CLI still uses it :(
I developed some CLIs in C and C++ for Linux and I am really surprised about webpack-cli behavior:

  1. It is run even with non existing option
    ./node_module/.bin/webpack-cli --xxxxxxxx

  2. It is run with wrong option
    ./node_module/.bin/webpack-cli --output-target--library # correct: --output-library-target

  3. It reads config file even when --config parameter is [ false | null | "" ]

./node_modules/.bin/webpack \
> --config "" \
> --entry ./test/es6/main.js \
> --output ./test/es6/main.bundle.js \
> --module-bind js=babel-loader \
> --mode development

More surprisingly there is a --no-color option that works while the --no-config has the real usability

20190418_134421

Thank you so much for your comment. Could you bring this over to https://github.com/webpack/webpack-cli/issues/820 ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anshumanv picture anshumanv  路  3Comments

fokusferit picture fokusferit  路  5Comments

anyulled picture anyulled  路  4Comments

jbottigliero picture jbottigliero  路  5Comments

heyalbert picture heyalbert  路  3Comments