preface
Pure hand translation, there are also a small part of the more blunt translation, forgive that part I do not understand 😂
Big changes
-
The environment
Nodejs 4 is not supported. The source code has been updated to a higher version of ECMAScript.
-
use
- You must choose one of the two modes (
mode
or--mode
) : Production or development- Production opens up all optimization features to create an optimized package
- Development opens comments and hints and enables the Eval DevTool functionality
- Production does not support listening mode, and Development has faster incremental builds
- You can go through
optimization.*
To set up more detailed configurations (build your custom schema) process.env.NODE_ENV
Variables have been set in both production and development modes (only in built code, not in configuration)- There is also a hidden
none
Mode, which disables everything
- You must choose one of the two modes (
-
grammar
import()
Always return an object with a namespace. The CommonJS module will be packaged into export default.- This is likely to break your code if you use it
import()
To import your CommonJS code.
- This is likely to break your code if you use it
-
configuration
- You no longer need to use these plugins:
NoEmitOnErrorsPlugin
->optimization.noEmitOnErrors
(Production mode is enabled by default.)ModuleConcatenationPlugin
->optimization.concatenateModules
(Production mode is enabled by default.)NameModulesPlugin
->optimization.nameModules
(Development mode is enabled by default)
CommonsChunkPlugin
Has been removed ->optimization.splitChunks
.optimization.runtimeChunk
- You no longer need to use these plugins:
-
JSON
- Webpack can now handle native JSON
- When you need to use the Loader to convert JSON to JS, you may need to add
type:"javascript/auto"
- It is also possible to use JSON without using a Loader
- When you need to use the Loader to convert JSON to JS, you may need to add
- Allows JSON to be imported using ESM syntax
- Unused export parts of JSON modules are eliminated
- Webpack can now handle native JSON
-
To optimize the
- update
uglifyjs-webpack-plugin
To the v1- ES2015 support
- update
Big functions
-
The module
-
Webpack now supports the following module types:
-
Javascript /auto:(default type in webpack 3) javascript modules within all modules
System support: CommonJS, AMD, ESM
-
Javascript/ESM: EcmaScript module, all other system module types will not be available
-
Javascript/Dynamic: only CommonJS and EcmaScript modules will not be available
-
Json: Json data, which can be obtained by require or import
-
Webassembly /experimental: WebAssembly module (currently experimental)
-
-
Javascript/ESM Avoiding javascript/ Auto is stricter when handling ESM
-
The imported name needs to exist in the imported module
-
Dynamic modules (non-ESM, such as CommonJS) are only available in import default
All other methods (including namespace imports) generate an error.
-
-
Javascript/ESM mode will be used by default in.mjs modules
-
WebAssembly module
- Other modules can be imported (JS and WASM)
- Modules exported from WebAssembly are verified by ESM import
- Active warning/error when you try to import a non-existent content from a WASM export.
- It can only be used in asynchronously loading chunks and does not work in initialized chunks. (Significant impact on page performance).
- through
import()
To import the WASM module
- through
-
-
To optimize the
-
SideEffects: False is now supported in package.json
- Inside the package. The json
sideEffect
Glob expressions and arrays of glob expressions are allowed
- Inside the package. The json
-
JSONP arrays have replaced JSONP functions with -> asynchronous script tag support, and order is no longer important.
-
Add the new option optimization.splitChunks
Details: gist.github.com/sokra/1522d…
-
Webpack itself removes obsolete branch code
- Before: Uglify removes unused code
- Now: Webpack removes unused code (same case)
- When it comes to discarded branch code it contains
import()
The removal operation will be stopped.
-
-
grammar
-
Import () supports black-tech comments: webpackInclude and webpackExclude.
They allow you to filter out some files when importing using dynamic expressions.
-
Using system.import () will prompt a warning
- You can go through
Rule.parser.system:true
Turn off these warnings - You can go through
Rule.parser.sustem:false
To disableSystem.import
- You can go through
-
-
configuration
- Can be achieved by
module.rules[].resolve
To configure the resolution mode. This will be combined with the global configuration. optimization.minimize
Has been added to the configuration with its minimize/compress function on/off.- This is enabled by default in Production mode and disabled by default in Development mode
optimization.minimizer
Has been added to the configuration to set compression handlers and options.
- Can be achieved by
-
use
- Some plug-in options have been disabled
- The CLI has migrated to Webpack-CLI, and you need to install Webpack-CLI to use the CLI
- The ProgressPlugin plug-in (–progress) now prints the name of the display plug-in
- At least for plug-ins that have migrated to the new plug-in system
-
performance
- UglifyJs is now cached and parallelized by default
- Lots of performance improvements, especially faster incremental builds
- RemoveParentModulesPlugin performance improvement
-
Stats
Stats now prints display hierarchy nesting in cascaded modules
function
- configuration
- Module types are automatically selected in MJS, JSON, and WASM extensions. Other extensions need to pass
module.rules[].type
In the configuration. - The wrong
options.dependencies
The configuration throws an error. sideEffects
This can be overridden by module.rulesoutput.hashFunction
It can now be a custom hash function- For performance reasons, you can provide a non-Cryto hash function
- add
output.globalObject
Config option to allow global object references to be selected in run time exitCode
- Module types are automatically selected in MJS, JSON, and WASM extensions. Other extensions need to pass
- The runtime
- Incorrect chunk loads now have more information and two new attributes
type
andrequest
- Incorrect chunk loads now have more information and two new attributes
- devtool
- Remove bottom comments in sourcemaps and Eval
- Soucemap added in Eval
include
test
和exclude
The support of
- performance
- The AST of Webpack can be passed correctly in the loader to avoid additional repetitive parsing
- Modules that are not used will no longer be associated
- Add a ProfillingPlugin that can write (Chrome) profiles containing timings
- The migration,
for of
Instead offorEach
- The migration,
Map
andSet
Instead of Objects - The migration,
includes
Instead ofindexOf
- Replace some string methods with regular expressions
- Queues no longer query the same job twice
- Use the faster MD4 hash for hashing by default
- To optimize the
- Shorter export names when using more than 25 exports
- Script tag is no longer added
text/javascript
andasync
Because they are the default values (save some bytes) - Serial modules generate less code
- Constant substitution is not required now
__webpack_require__
And parameters have been deleted
- The default
- Webpack will now press
.wasm
..mjs
..js
..json
Extension to find files sequentially output.pathinfo
Development mode is now enabled by default- Production mode disables memory caching by default
entry
The default point to./src
output.path
The default point to./dist
- Production mode is used by default when mode is not specified
- Webpack will now press
- grammar
- Context supported resource query
- in
import()
The name of an entry node applied in the system changes from a warning to an error - Update ACorn5 to support ES2018
- The plug-in
done
Now it’s an asynchronous hook
Bug fix
- Comment creation will no longer be interrupted by */
- Webpack no longer modifies past option objects
- The compiler “watch-run” hook now contains the compiler itself as the first argument
- add
output.chunkCallbackName
To allow the webworker template to be configured - use
mdoule.id/loaded
Can jump out of module links correctly (scope promotion) - OccurenceOrderPlugin now sorts modules correctly (not the other way around)
- When calling
Watching.invalidate
The timestamp of the file is retrieved from the listener - Fix incorrect post loader
-!
behavior - in
MultiCompiler
addrun
andwatchRun
hook - In the ESM
this
Will beundefined
- Can be achieved by
var
.let
.const
To make the correct variable declaration - The parser is now using module types
javascript/dynamic
orjavascript/module
, parse the source code with the correct source code (module/script). - In case of
buildMeta
Of Null does not interrupt module loss - Add in the electron target
original-fs
The module - HMRPlugin can
plugins
Add to the compiler
Internal changes
- use
tap
Call to replaceplugin
Call (new plug-in system) - Migrate many abandoned plug-ins to the new plug-in system API
- add
buildMeta.exprotsType:default
Into the JSON module - Don’t remove parser functions (parserStringArray parserCalculatedStringArray)
- Remove to remove
BasicEvaluatedExpression
And the ability to have multiple types - Replace the new Buffer with buffur. from
- Avoid forEach and use for of instead
- with
neo-async
Instead ofasync
- Update the exploitable and enhanced-resolve dependencies to the new major version
- Using a Prettier
Removed features
-
Remove the module loaders
-
Remove loaderContext. The options
-
Remove the Compliation.notCacheable flag
-
Remove NoErrorsPlugin
-
Remove the Dependency. IsEqualResource
-
Remove NewWatchingPlugin
-
Remove CommonsChunkPlugin
Destructive changes for plug-ins/loaders
- New plug-in system
plugin
Method backward compatibility- Plug-ins should use
Compiler.hooks.xxx.tap(<plugin name>, fn)
- New major version enhanced parsing
- The Chunks template can now generate multiple assets
Chunk.chunks/parents/blocks
It’s no longer an array. Internally, a Set is used, and there are methods to access it.Parser.scope.renames
andParser.scope.definitions
Instead of Object/Array, Map/Set.- Parser use
StackedSetMap
(LevelDB array structure) instead of an array - No longer set when applying plug-ins
Compiler.options
- As a result of refactoring, harmonious dependencies have changed
Dependency.getReference()
One will now be returnedweak
Properties.Dependency.weak
Has now beenDependency
Is used by the base class ofgetReference()
From the internal base IMPL- Constructor arguments to all
module
change - merge
ContextModule
andresolveDependencies
The options in the - Change and rename
import()
Dependency inside - The migration
Compiler.resolvers
toCompiler.resolverFactory
To make it accessible to the plug-in Dependency.isEqualResource
beDependency.getResourceIdentifier
replaceTemplate
The methods inside are now static methods- Add a new RuntimeTemplate class,
outputOptions
andrequestShortener
Migrate to this class- Many methods are updated to use RuntimeTemplate instead
- We plan to move code that has access to the runtime to a new class
Module.meta
beModule.buildMeta
alternative- new
Module.buildInfo
andModule.factoryMeta
Module
Some properties are moved to a new object- Add that point
context
Of the optionsloaderContext.rootContext
. Loaders may need it to create content relative to the program root - new
this.hot
Flags to the loader context when HMR is enabled buildMeta.harmony
bebuildMeta.exportType: "namespace"
alternative- The Chunk diagram has changed:
- Previously: Chunks are related to each other through parent-child relationships
- Now: Chunk groups are associated through parent-child relationships, and chunk groups contain chunks
- Before: Asynchronously dependent blocks reference a set of chunks
- Now: Asynchronous dependencies reference a single chunk group
- File /contextTimstamps is now Maps
map/foreach
Chunks/Modules/Parents
The method has been removed- NormalModule receives the option object in the constructor
- Add the necessary build parameters to NormalModule
- Inside NormalModuleFactory
createGenerator
andgenerator
Hooks are generated in custom code - Allows custom rendering of Chunks mainfest via hooks