GeezerVison is showing github.com — webpack-cli v4 beta feedback and changes · Issue #1222 · webpack/webpack-cli
webpack-cli v4 beta feedback and changes #1222DescriptionAbout v4
With webpack-cli v4 we will support only webpack v5 and possibly v4 but not officially, so if there are any problems we suggest to use v3.* if you still want to keep the best compatibility.
We dropped Node.js 8 from our CI. We support at least Node.js 10.
What's changing
Less arguments
We drastically reduced the number of arguments that we support. This is because we think most of them are not used by anyone (or used inside a configuration file). Run
To check the arguments supported.
If you think that we wrongly removed an argument that you thought it was useful, please leave a comment here and we can discuss its implementation. (add a 👍 if someone already requested an argument you need)
.webpack folder support
The CLI now supports the .webpack folder by default. This feature is still in beta so it would be great if people could start using it. Files that are automatically imported:
.webpack/webpack.config.dev
.webpack/webpack.config.prod
.webpack/webpackfile
webpack.config
Changed default output
We wanted to change a bit the output emitted via CLI.
✅ Compilation Results
🌏 Version: 5.0.0-beta.12
⚒️ Built: Wed Feb 12 2020 09:05:53 GMT+0100 (Central European Standard Time)
⏱ Compile Time: 265ms
📂 Output Directory: /Users/***/www/webpack-cli/test/entry/defaults-index/dist
#️⃣ Hash: 0b145a012a5ce8805b14
┌────────────┬───────────────────────────────┐
│ Entrypoint │ Bundle │
├────────────┼───────────────────────────────┤
│ main │ Bundle Name │ main.js │
│ │ Compared For Emit │ true │
│ │ Bundle size │ 0.00 kb │
│ │ │
│ │ Modules: │
│ │ ./index.js [size: 1 bytes] │
└────────────┴───────────────────────────────┘
Don't worry, you can still go to the old output using the --standard flag.
Arguments --dev and --prod
Now you can pass the mode to the compiler using these two simple arguments.
Help for single arguments
Running the following command
Will output
Usage: webpack --dev
Description: Run development build
Documentation: https://webpack.js.org/concepts/#mode Activityt-fritsch commented on Feb 13, 2020 Hello,
I tested beta2 unintentionally with my students very quickly 2 days ago (In fact I didn't notice until they told me that the options I asked them to use were throwing errors, when I realized 4.0.0-beta2 had just been published I told them to downgrade to make my exercise work ! 😄 )
Not a big deal but even if I understand the point of having clean and concise --dev and --prod options, I think the --mode= option better matches the way it works in configuration file and is more straightforward when you already know configuration file. Just my 2 cents, but I'm not sure a breaking change in this area is really useful ?
Anyway, thanks for the great work here 👏 Reacted by Emanuele Stoppa, Constantine Antonakos, Alfredo Peres and Arthur Beaulieu Reacted by Emanuele Stoppa and Constantine Antonakos jhnns commented on Feb 14, 2020 Hey ho 👋
Removing some of the flags is a good idea 👍
But there are two features I really use a lot that are currently not implemented in v4:
-
Passing --env: I personally don't like to split the configuration into separate files since it becomes very hard to understand what the final configuration is going to be. I respect that some people prefer to split the configuration but I think that the webpack-cli should also support single-file configurations. And for single-file configs, the --env feature is really nice. This has already been requested in Unknown argument: --env #1216.
-
Using TypeScript in webpack configs: If I try to run webpack with a webpack.config.ts it currently throws an error:
webpack: TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received type undefined
at validateString (internal/validators.js:112:11)
at Module.require (internal/modules/cjs/loader.js:841:3)
at require (internal/modules/cjs/helpers.js:74:18)
at [...]/node_modules/webpack-cli/lib/groups/ConfigGroup.js:66:39
at Array.forEach (<anonymous>)
at ConfigGroup.requireConfig ([...]/node_modules/webpack-cli/lib/groups/ConfigGroup.js:65:33)
at Array.map (<anonymous>)
at ConfigGroup.resolveConfigFiles ([...]/node_modules/webpack-cli/lib/groups/ConfigGroup.js:144:44)
at ConfigGroup.run ([...]/node_modules/webpack-cli/lib/groups/ConfigGroup.js:183:14)
at WebpackCLI._handleGroupHelper ([...]/node_modules/webpack-cli/lib/webpack-cli.js:212:40) {
code: 'ERR_INVALID_ARG_TYPE'
}
The configModule in ConfigGroup.prototype.requireConfig looks like this:
{
path: '[...]/webpack.config.ts',
ext: '.ts',
module: [
'ts-node/register',
'typescript-node/register',
'typescript-register',
'typescript-require',
{ module: '@babel/register', register: [Function: register] }
]
}
Is this a bug or are you planning to drop support for TypeScript configs? Using TS in webpack configs is really nice because of Intellisense and type checking.
I'm going to present both features in my upcoming talk next week at the Frontend Developer Love Conference in Amsterdam and I don't want to advertise deprecated features 😁. Reacted by Emanuele Stoppa, Constantine Antonakos, Alfredo Peres, Nitin Kumar, Roland Schläfli, Hugo Häggmark, Nicholas Pedroso, Alan Dávalos and Arthur Beaulieu jpreynat commented on Feb 20, 2020 Hi,
Following @jhnns message, using a file webpack.config.babel.js also leads to an error after switching from webpack 3 to the 4.0.0-beta.3:
Error: Cannot find module 'babel-register'
Are support for babel and typescript been made opt-in using peer-dependencies?
It seems that switching to .mjs works, but it would be great to know what we can/can't do with the new beta.
Thanks in advance. ematipico commented on Feb 22, 2020 ContributorAuthor More actions Seamless support for typescript and babel is not deprecated, it was a bug. We're working on restoring these features :) exKAZUu commented on Mar 2, 2020 @ematipico 4.0.0-beta.7 doesn't work well due to Error: Cannot find module '@webpack-cli/logger'. The published @webpack-cli/[email protected] package seems to contain no lib directory as follows:
$ pwd
/Users/XXXX/test/node_modules/@webpack-cli/logger
$ ls
CHANGELOG.md LICENSE README.md package.json
Reacted by Emanuele Stoppa ematipico commented on Mar 2, 2020 ContributorAuthor More actions Thank you @exKAZUu , I will check this out ematipico commented on Mar 2, 2020 ContributorAuthor More actions @exKAZUu the latest beta should work now! Reacted by Sakamoto, Kazunori exKAZUu commented on Mar 3, 2020 chumbalum commented on May 14, 2020 I second @jhnns comment on the --env parameter. It's pretty handy for single file configs and should be kept in my opinion. Reacted by Arthur Beaulieu mstssk commented on May 25, 2020 4.0.0-beta.8 does not fails when errors occur in loaders.
For example:
ts-loader raise a error when compiling wrong typescript code, however webpack returns exit code 0. alexander-akait commented on May 25, 2020 @mstssk Can you open a new issue with reproducible test repo? mstssk commented on May 25, 2020 criles25 commented on May 26, 2020 I am trying to write my webpack.config.js as a function, e.g.,
module.exports = function(env, argv) {
...
but the v4 beta doesn't seem to recognize it. Does this syntax no longer work?
i was wanting to read env vars in my webpack config file, is there some other way to get access to env vars in the config?
also, i'm enjoying the new features. the webpack serve is working great, and the --prod flag if helpful. thanks. Reacted by Adrien and Anshuman alexander-akait commented on May 26, 2020 /cc @webpack/cli-team Need to add test with config like a function alexander-akait commented on Aug 10, 2020 We will try to do the next release on this week Reacted by Riley, Axetroy, Ivan Demchuk, Ryan Roemer and Nicholas Pedroso eamodio commented on Sep 2, 2020 Any update on a new beta release? alexander-akait commented on Sep 2, 2020 @webpack/cli-team friendly ping, we need to finish PRs billyjanitsch commented on Sep 23, 2020 Please, please reconsider having webpack-cli depend directly on @webpack-cli/init (#1609). The latter is an enormous module with so many dependencies (particularly jscodeshift, which is huge and very outdated). This doesn't affect bundle size, of course, but it does affect install time and npm's ability to dedupe modules. Plus, the init functionality is only useful when initializing a project, and most projects probably don't use it to initialize themselves anyway.
This issue came up back when webpack v4 was in beta. There's nothing wrong with @webpack-cli/init existing, but webpack-cli is currently required to invoke webpack via CLI and it would be really nice to have some way of doing this without bringing in half of the npm registry. All that most people need is to be able to add a simple build script to package.json. webpack-cli v3 did the right thing by including only this minimal core.
In an empty project, npm install webpack-cli@next (4.0.0-rc.0) currently installs 82mb of dependencies (!) whereas npm install webpack-cli@3 only installs 6mb. Reacted by Ryan Lopopolo and Ankur K alexander-akait commented on Sep 24, 2020 billyjanitsch commented on Sep 24, 2020
https://arve0.github.io/npm-download-size/#webpack-cli@next
@evilebottnawi that website is only tracking the size of direct dependencies. For example, it shows 12.11 MiB but if you click on @webpack-cli/init @ 1.0.1-rc.0 -- 11.3 MiB (606 deps) it shows 19.44 MiB, and so on, recursively.
Try this:
mkdir foo
cd foo
npm install webpack-cli@next
du -sh node_modules/
You get:
alexander-akait commented on Sep 24, 2020 billyjanitsch commented on Sep 24, 2020 mwmcode commented on Oct 12, 2020 Can we have the default folder name as webpack instead of .webpack?
Webpack config is an important part of any app that uses it, so we should (IMHO) use a not-dotted folder them so they're not hidden by the OS. Reacted by Ruslan @doasync alexander-akait commented on Oct 12, 2020 @mustafawm you can use any directory name and use require/import, I want to close this issue, because we done webpack-cli v4 and want to focus on fixing bugs dmurvihill commented on Oct 23, 2020 --dev and --prod are nice, but since --env has been removed what do you suggest for projects that have more than two configurations (for instance, I need --staging)
anshumanv commented on Oct 23, 2020 Hi @dmurvihill, we added env back since it was requested by quite a lot of folks.
You can do --env environment=staging and read it in your config
const { environment } = env
if(environment === "staging") {
return { ... }
}Reacted by Dolan Murvihill AlonMiz commented on Nov 1, 2020
--dev and --prod are nice, but since --env has been removed what do you suggest for projects that have more than two configurations (for instance, I need --staging)
my suggestion is not to have staging config at all. the staging config should be prod.
i know that sounds strict but staging should be compiled the same way as prod.
in most of my use cases i've seen, this assumption can work as we can inject the ENV=staging in the runtime of the server (eg. nginx), so that we have ONE SINGLE docker image that holds our service serving those static files, both for prod and for staging. while injecting the env staging to that docker will inject env=staging to the main html, then you can use config to distinguish these envs.
having the same image for both staging/local/prod is a great advantage for consistency and testability
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|