Google缓存每天只更新一到两次,站点在任何构建的缓存页面上都会被破坏。有一个请求,以避免一个坏掉的谷歌缓存的网站在任何建设。因此,一个解决方案是从js文件的名称中间删除contenthash。并删除css文件的散列。
发布于 2022-08-28 08:48:24
将下一段代码推送到next.config.js
module.exports = {
webpack(config, options) {
if (!options.dev) {
const NextMiniCssExtractPlugin = config.plugins[11];
config.output.filename = config.output.filename.replace('-[contenthash]', '');
config.output.chunkFilename = config.output.chunkFilename.replace('.[contenthash]', '');
config.module.generator.asset.filename = config.module.generator.asset.filename.replace('.[hash:8]', '');
if (NextMiniCssExtractPlugin) {
NextMiniCssExtractPlugin.options.filename = NextMiniCssExtractPlugin.options.filename.replace('[contenthash]', '[name]');
NextMiniCssExtractPlugin.options.chunkFilename = NextMiniCssExtractPlugin.options.chunkFilename.replace('[contenthash]', '[name]');
}
}
return config;
},
...
}此代码从nextjs的构建配置文件名中删除contenthash和散列:8。它允许在js和css文件的构建目录中有没有散列的文件名。
https://stackoverflow.com/questions/73517245
复制相似问题