首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从js和css文件的名称中删除contenthash (散列)

问如何从js和css文件的名称中删除contenthash (散列)
EN

Stack Overflow用户
提问于 2022-08-28 08:46:07
回答 1查看 50关注 0票数 0

Google缓存每天只更新一到两次,站点在任何构建的缓存页面上都会被破坏。有一个请求,以避免一个坏掉的谷歌缓存的网站在任何建设。因此,一个解决方案是从js文件的名称中间删除contenthash。并删除css文件的散列。

EN

回答 1

Stack Overflow用户

发布于 2022-08-28 08:48:24

将下一段代码推送到next.config.js

代码语言:javascript
复制
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文件的构建目录中有没有散列的文件名。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73517245

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档