您好,欢迎访问一九零五行业门户网

Webpack3有哪些新特性

本文简短地分享下最新发布的 webpack 3 中的新特性,供大家参考。
1. webpack 3 的新特性6 月 20 日,webpack 发布了最新的 3.0 版本,并在 medium 发布了公告。
webpack 目前几乎作为前端开发的标配,所以我们一起来看一看新版中有哪些主要的特性更新。
整体相对于 2.0 变化不大,不必惊慌。
webpack 2.0 的相关视频教程,可以参见我录制的共计 20 集的视频教程,webpack 2 视频教程。
下面是 v3.0 release 中的 features list。
node_modules no longer mangle to ~ in stats [breaking change]
timeout for hmr requests is configurable
added experimental scope hoisting (webpack.optimize.moduleconcatenationplugin)
some performance improvements
added output.libraryexport to select an export for the library
sourcemapfilename now supports [contenthash] [breaking change]
module.noparse supports functions
add node: false option to disable all node specific additions
1.1 更新方法以及版本迁移通过命令直接安装即可,后面需要加上版本号。
npm install webpack@3.0.0 --save-dev
或者
yarn add webpack@3.0.0 --dev
至于从 webpack 2 升级到 webpack 3,官方的原话是:
no effort beyond running the upgrade commands in your terminal
所以可以断定,虽然版本号进行了大版本号的变更,不过并不会有太大的变化,可以松一口气了。
1.2 scope hoisting之前的每一个 module 都被包含在一个独立的 function closures 中,这样的处理方式就造成了在代码在浏览器中执行缓慢的问题。
开发团队参考了 closure compiler 和 rollupjs 等框架后,将 function closures 的包裹方式变成了可配置的形式。
就是在之前的 plugins 中配置即可。
module.exports = {     plugins: [     new webpack.optimize.moduleconcatenationplugin()   ] };
当然可能因为某些模块的加载导致不能配置成功,官方提供了 cli 的参数 --display-optimization-bailout 用于 debug 是什么原因导致了配置失败。
1.3 magic comments其实就是可以命令 chunk name 了。
import(/* webpackchunkname: my-chunk-name */ 'module');
更多的使用可以参考这里。
2. 接下来的新特性更好的编译缓存
更快的首次以及增量编译速度
对 typescript 更加友好地支持
修改 long term caching
增加对 wasm module 的支持
用户体验的改进
3. 总结总体看来变化不大,而且如 magic comments 等功能就已经在 2.4 的版本中发布了,个人感觉,发布一个 3.0 的版本主要是团队提供更好产品的一个决心象征吧。
以上就是webpack3有哪些新特性的详细内容。
其它类似信息

推荐信息