You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Quasar构建时禁用缓存清除哈希或自定义命名规则?

解决Quasar构建时禁用内容哈希/自定义文件命名的问题

一、禁用内容哈希的正确配置

你之前的配置位置有误——filenameHashing需要放在顶层的build对象下,而非嵌套在supportTS中。修正后的quasar.conf.js配置如下:

module.exports = configure(function(ctx) {
  return {
    // https://quasar.dev/quasar-cli/supporting-ts
    supportTS: {
      tsCheckerConfig: {
        eslint: {
          enabled: true,
          files: './src/**/*.{ts,tsx,js,jsx,vue}'
        }
      }
    },
    // 核心:build配置置于顶层
    build: {
      filenameHashing: false, // 彻底禁用内容哈希后缀
      // 其他构建相关配置...
    }
  }
})

配置生效后,构建输出的JS、CSS文件会去掉哈希后缀(例如从app.abc123.js变为app.js),避免缓存机制导致的文件名自动变更。

二、自定义文件重命名规则

如果需要更灵活的命名逻辑(比如自定义哈希长度、按模块分组命名),可以通过Quasar提供的webpack配置扩展能力实现,直接修改webpack的output相关规则:

方法1:用configureWebpack直接覆盖输出配置

module.exports = configure(function(ctx) {
  return {
    build: {
      configureWebpack: {
        output: {
          // 主文件命名:保留6位哈希+原模块名
          filename: '[name].[chunkhash:6].js',
          // 异步chunk文件:放到chunks目录下
          chunkFilename: 'chunks/[name].[chunkhash:6].js',
          // 静态资源(图片、字体等):放到assets目录下
          assetModuleFilename: 'assets/[name].[hash:6][ext]'
        }
      }
    }
  }
})

方法2:用chainWebpack链式修改配置(更灵活)

module.exports = configure(function(ctx) {
  return {
    build: {
      chainWebpack(chain) {
        // 调整JS文件输出规则
        chain.output
          .filename('[name].[contenthash:8].js')
          .chunkFilename('async-chunks/[name].[contenthash:8].js');
        
        // 调整CSS文件输出规则(适配Quasar集成的mini-css-extract-plugin)
        chain.plugin('extract-css')
          .tap(args => {
            args[0].filename = 'styles/[name].[contenthash:8].css';
            args[0].chunkFilename = 'styles/async/[name].[contenthash:8].css';
            return args;
          });
        
        // 调整静态资源输出规则
        chain.module.rule('assets')
          .set('generator', {
            filename: 'static/[name].[hash:6][ext]'
          });
      }
    }
  }
})

你可以根据需求调整占位符:[name]对应模块原名称,[chunkhash]/[contenthash]对应内容哈希,[ext]对应文件扩展名,组合出符合需求的命名规则。

内容的提问来源于stack exchange,提问作者scott

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 11:02:38