webpack - where does webpack cache its work for rebuilding?
问题描述
This page shows a lot of compilation modes for webpack, and some of them rebuild faster than they build.
I am trying to measure the speed of different build-tools, but I can't figure out if I am building or rebuilding. I mean.. what files do I have to clear to make sure that I am rebuilding? Just the target directory? Or is there another cache somewhere?
For example is the second build here a build or a rebuild the second time?
node_modules/.bin/webpack --output-path ~/target
rm -r target
node_modules/.bin/webpack --output-path ~/target
if that rebuilds, what to I have to clear to make it build again?
and does the second one here build or rebuild?
node_modules/.bin/webpack --output-path ~/target
node_modules/.bin/webpack --output-path ~/target
And if that is another build, what do I have to do to rebuild?
(webpack 4)
解决方案
TL;DR: “重建”仅在watch
mode或development
mode期间发生。
网页包
Webpack 似乎没有缓存到文件中,而只是在内存中。
缓存
缓存生成的 webpack 模块和块以提高构建速度。在 watch 模式和 webpack 设置为开发模式时,默认情况下会自动启用缓存。
由于默认情况下它仅在开发和监视模式下启用,因此您的每个命令都应该是全新的构建。您可以确定关闭此cache
选项,也可以专门针对production
:
node_modules/.bin/webpack --output-path ~/target --mode=production
我在查看 webpack 5 中的新更改后立即遇到了这个问题,其中之一是允许缓存到本地文件。
cache
:对象已删除:不再可能设置为内存缓存对象
cache.type
补充:现在可以在“内存”和“文件系统”之间进行选择
我认为这意味着当前在 webpack 4 中不可能在文件系统中缓存。
编辑:你没有在问题中提到它,但我刚才看到你babel
在赏金的推理中提到了。
通天塔
如果您使用babel-loader
,则默认情况下有一个cacheDirectory
选项false
。但是,如果启用,默认目录位于node_modules/.cache/babel-loader
.
这是文档中关于它的片段,强调我的:
cacheDirectory
:默认为假。设置后,给定目录将用于缓存加载程序的结果。未来的 webpack 构建将尝试从缓存中读取,以避免在每次运行时都需要运行可能代价高昂的 Babel 重新编译过程。如果在 options 中将该值设置为 true({cacheDirectory: true})
,则加载程序将使用默认缓存目录,如果在任何根目录中都找不到文件夹,node_modules/.cache/babel-loader
则将回退到默认 OS 临时文件目录。node_modules
推荐阅读
- c++ - 具有 OpenGL + GLSL 集成的 Qt 程序在运行时立即崩溃
- r - 通过“$”和字符串变量访问 R 数据框
- shopify - 仅更改一页的 page_title 值
- angular - 星云聊天机器人;在对话中发送文件(图片),文档不完整?
- python - 如何对要下载的推文设置限制?
- botframework - 在 Azure 聊天机器人的 Directline 语音中添加对各种口音的支持
- javascript - CSS/JS 未链接到 HTML 页面
- c# - 用 DataTable 填充的 SqlDataAdapter 不起作用
- hibernate - spring data jpa 如何管理每个事务的会话?
- git - Azure ML,DevOps:在分支之间切换会保留来自另一个分支的一些文件