你可以删除文件夹 "node_modules/.cache" 以强制Webpacker/Babel重新构建它们的缓存。
node_modules/.cache/webpack
(使用npm时)或.yarn/.cache/webpack
(使用Yarn Plug'n'Play API)中,详见Persistent Caching。cache:false
来完全停用缓存。node_modules/.cache/webpack
或.yarn/.cache/webpack
.cache
目录。在删除.cache
后,我不得不重新启动开发服务器才能看到更改了"node_modules"目录中文件的效果。如果这能帮到其他人,我有一个类似的情况,问题在于我的导入语句中有一个大写字母。例如,我有这样一行代码:
import {Person} from './model/Model';
import {Person} from './model/model';
一切都恢复正常了。
我遇到了一个类似的问题,只是webpack缓存了CSS文件。我的angular工作区没有node_modules/.cache
文件夹,但是删除了.angular/cache
文件夹后问题得到了解决。在删除该文件夹后,我还必须停止并重新启动ng serve
命令。
cache: false
。这对我在Next.js上运行时有效。three.js
副本,当您忽略大小写时,它们具有相同的有效名称:'three'与'THREE'相同。src
属性中添加查询参数,然后调用一个函数在文件加载时执行其他脚本:<script type="text/javascript">
var script = document.createElement('script');
script.type = 'text/javascript';
script.onload = function () {
init(); // call other scripts when this file is fully loaded
};
script.src = 'dist/bundle.js?v='+Date.now();
document.getElementsByTagName('body')[0].appendChild(script);
</script>
<script>
function init(argument) {
// other scripts
console.log('dist/bundle.js is loaded from the server not from the cache')
}
</script>
参见:在JS中动态加载JS
Webpack没有缓存,但浏览器有。Webpack编译生成的文件可以保持缓存,除非它们的内容发生了变化。在文档中,他们解释说为了解决这个问题,你可以在输出文件名中添加[contenthash]。
[contenthash]替换将基于资产内容添加唯一哈希。当资产内容更改时,[contenthash]也会更改。
module.exports = {
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist')
}
};
PS:我正在使用Webpack v4.30.0
更多信息,请查看Webpack缓存指南。
eslint-loader
时遇到了一个问题,出现了有关先前文件系统状态的错误。删除该目录似乎解决了这个问题。 - daniels