Issues with getting started with webpack 4

我的未来我决定 提交于 2019-11-28 22:50:30

You can pass mode param in the webpack config or cli command.

Config: mode: 'development' or mode: 'production'

CLI: webpack --mode development or webpack --mode production

The Webpack team is working on updating the package docs asap. New guides and docs are available in the webpack.js.org official site.

In the meantime, You can also read related posts on medium:

Check on GitHub this Webpack-Demo project intended to be a Webpack 4 tutorial. Previous and others links to helpful resources used in the webpack configs are included in the project's Readme. It has two zero-config builds (using the new webpack mode option which includes a sets of defaults), and another two using custom configs.


Since , the CLI has been move to webpack-cli therefore you need to install also this package in your devDependencies. Also, expect the new mode configuration to be set either on the CLI run or the config object.

CLI usage in your npm scripts:

"scripts": {
    "dev": "webpack --mode development",
    "prod": "webpack --mode production"
}

Set mode property in your webpack config object:

{
    mode: 'production' // | 'development' | 'none'
}

If mode value isn't specified, webpack uses the production value (defaulted option). But warns you in the output with:

WARNING in configuration

The 'mode' option has not been set. Set 'mode' option to 'development' or 'production' to enable defaults for this environment.

Webpack mode reduce the required configuration for an useful build by using a set of defaults (default values for configuration properties depending the mode value):

  • production enables all kind of optimizations to generate optimized bundles
  • development enables useful error messages and is optimized for speed
  • none is a hidden mode which disables everything

Read more on release notes & changelog

It will be updated very soon, see this link for information

We are very close to having out Migration Guide and v4 Docs Additions complete! To track the progress, or give a helping hand, please stop by our documentation repository, checkout the next branch, and help out!

Got the same issue and after a bit of research found its a problem to be fixed as you can see on this Github thread

One of the options:

Inside package.json set scripts to either development or production mode

"scripts": {
  "dev": "webpack --mode development",
  "build": "webpack --mode production"
}

And now when you run npm run dev it will give you bundle.js but not minified.

But when you run npm run build it will give you a minified bundle

Webpack 4 docs are not ready yet. I recently migrated from webpack 3 to 4 and it took me quite some time to figure out all the issues.

Here'a my sample repo you can use as reference for migrating from webpack 3 to 4.

https://github.com/flexdinesh/react-redux-boilerplate

There's one commit specific for migration. Take a look at that for more info.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!