-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
add migration guide #1939
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
add migration guide #1939
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dc072b6
add migration guide
sokra a570154
Merge branch 'master' into content/migration-4
EugeneHlushko 7c848bb
docs(guides) Migrate v3 to v4
EugeneHlushko e3ab76f
docs(guides) Make migration guide titles consistent
EugeneHlushko 8691f8e
Merge branch 'master' into content/migration-4
sokra 41273df
Merge branch 'master' into content/migration-4
montogeek 9b6c80d
Merge branch 'master' into content/migration-4
montogeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
--- | ||
title: To webpack v2, v3 | ||
sort: 1 | ||
title: To v2 or v3 from v1 | ||
sort: 2 | ||
contributors: | ||
- sokra | ||
- jhnns | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
--- | ||
title: To v4 from v3 | ||
sort: 1 | ||
contributors: | ||
- sokra | ||
- EugeneHlushko | ||
--- | ||
|
||
This guide only shows major changes that affect end users. For more details please see [the changelog](https://github.com/webpack/webpack/releases). | ||
|
||
|
||
## Node.js v4 | ||
|
||
If you are still using Node.js v4 or lower, you need to upgrade your Node.js installation to Node.js v6 or higher. | ||
|
||
|
||
## CLI | ||
|
||
The CLI has moved to a separate package: webpack-cli. You need to install it before using webpack, see [basic setup](/guides/getting-started/#basic-setup). | ||
|
||
|
||
## Update plugins | ||
|
||
Many 3rd-party plugins need to be upgraded to their latest version to be compatible. | ||
|
||
|
||
## mode | ||
|
||
Add the new [`mode`](/concepts/mode/) option to your config. Set it to production or development in your configuration depending on config type. | ||
|
||
__webpack.config.js__ | ||
|
||
``` diff | ||
module.exports = { | ||
// ... | ||
mode: 'production', | ||
} | ||
``` | ||
|
||
Alternatively you can pass it via CLI: `--mode production`/`--mode development` | ||
|
||
## Deprecated/Removed plugins | ||
|
||
These plugins can be removed from configuration as they are default in production mode: | ||
|
||
__webpack.config.js__ | ||
|
||
``` diff | ||
module.exports = { | ||
// ... | ||
plugins: [ | ||
- new NoEmitOnErrorsPlugin(), | ||
- new ModuleConcatenationPlugin(), | ||
- new DefinePlugin({ "process.env.NODE_ENV": JSON.stringify("production") }) | ||
- new UglifyJsPlugin() | ||
], | ||
} | ||
``` | ||
|
||
These plugins are default in development mode | ||
|
||
__webpack.config.js__ | ||
|
||
``` diff | ||
module.exports = { | ||
// ... | ||
plugins: [ | ||
- new NamedModulesPlugin() | ||
], | ||
} | ||
``` | ||
|
||
These plugins were deprecated and are now removed: | ||
|
||
__webpack.config.js__ | ||
|
||
``` diff | ||
module.exports = { | ||
// ... | ||
plugins: [ | ||
- new NoErrorsPlugin(), | ||
- new NewWatchingPlugin() | ||
], | ||
} | ||
``` | ||
|
||
|
||
## CommonsChunkPlugin | ||
|
||
The `CommonsChunkPlugin` was removed. Instead the [`optimization.splitChunks`](/configuration/optimization/#optimization-splitchunks/) options can be used. | ||
|
||
See documentation of the [`optimization.splitChunks`](/configuration/optimization/#optimization-splitchunks/) for more details. The default configuration may already suit your needs. | ||
|
||
T> When generating the HTML from the stats you can use `optimization.splitChunks.chunks: "all"` which is the optimal configuration in most cases. | ||
|
||
## import() and CommonJS | ||
|
||
When using `import()` to load non-ESM the result has changed in webpack 4. Now you need to access the `default` property to get the value of `module.exports`. | ||
|
||
__non-esm.js__ | ||
|
||
``` javascript | ||
module.exports = { | ||
sayHello: () => { | ||
console.log('hello world'); | ||
} | ||
}; | ||
``` | ||
|
||
__example.js__ | ||
|
||
``` javascript | ||
function sayHello() { | ||
import('./non-esm.js').then(module => { | ||
module.default.sayHello(); | ||
}); | ||
} | ||
``` | ||
|
||
## json and loaders | ||
|
||
When using a custom loader to transform `.json` files you now need to change the module `type`: | ||
|
||
__webpack.config.js__ | ||
|
||
``` diff | ||
module.exports = { | ||
// ... | ||
rules: [ | ||
{ | ||
test: /config\.json$/, | ||
loader: 'special-loader', | ||
+ type: 'javascript/auto', | ||
options: {...} | ||
} | ||
] | ||
}; | ||
``` | ||
|
||
When still using the `json-loader`, it can be removed: | ||
|
||
__webpack.config.js__ | ||
|
||
``` diff | ||
module.exports = { | ||
// ... | ||
rules: [ | ||
{ | ||
- test: /\.json$/, | ||
- loader: 'json-loader' | ||
} | ||
] | ||
}; | ||
``` | ||
|
||
## module.loaders | ||
|
||
`module.loaders` were deprecated since webpack 2 and are now removed in favor of [`module.rules`](/configuration/module/#rule). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep titles consistent.