question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Disable filenameHashing, but add hash as query parameter in index.html

See original GitHub issue

What problem does this feature solve?

Hi, I want to disable filenameHashing, but instead want to add the hash as query param to the injected resources in index.html, like <script src="/js/chunk-vendors.js?_hash=0d01e0b2c53c417bdcfd"></script>. Thus, the resources loaded via index.html will still be fetched if changed even if they got a long cache expiry. Is this possible somehow? Thanks!

What does the proposed API look like?

<script src="/js/chunk-vendors.js?_hash=0d01e0b2c53c417bdcfd"></script>

or

<script src="/js/chunk-vendors.js?_version=0d01e0b2c53c417bdcfd"></script>

maybe via a setting in vue.config.js like addFilenameHashAsQueryParam

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

5reactions
fangbinweicommented, Oct 24, 2020

You can overwrite the webpack config

Update: Strongly recommend use css config in vue.config.js


/** @type {import('@vue/cli-service').ProjectOptions} */
module.exports = {
+  css: {
+   extract: {
+      filename: 'css/[name].css?_hash=[contenthash:8]',
+      chunkFilename: 'css/[name].css?_hash=[contenthash:8]'
+    }
+  },
  chainWebpack: (config) => {
    if (process.env.NODE_ENV === 'production') {
      config
        .output
        .filename('js/[name].js?_hash=[contenthash:8]')
        .chunkFilename('js/[name].js?_hash=[contenthash:8]')

-      config.plugin('extract-css').tap(args => {
-        args[0].filename = 'css/[name].css?_hash=[contenthash:8]'
-        args[0].chunkFilename = 'css/[name].css?_hash=[contenthash:8]'
-        return args
-      })
    }
  },
}

vue.config.js

/** @type {import('@vue/cli-service').ProjectOptions} */
module.exports = {
  chainWebpack: (config) => {
    if (process.env.NODE_ENV === 'production') {
      config
        .output
        .filename('js/[name].js?_hash=[contenthash:8]')
        .chunkFilename('js/[name].js?_hash=[contenthash:8]')

      config.plugin('extract-css').tap(args => {
        args[0].filename = 'css/[name].css?_hash=[contenthash:8]'
        args[0].chunkFilename = 'css/[name].css?_hash=[contenthash:8]'
        return args
      })
    }
  },
}
1reaction
mtskfcommented, Jun 14, 2022

@fangbinwei @herrernst With the solution above, app-legacy.js isn’t generated. Here’s my solution:

config.output.filename((process.env.VUE_CLI_MODERN_MODE && process.env.VUE_CLI_MODERN_BUILD) ? 'js/[name].js?_hash=[hash:8]' : 'js/[name]-legacy.js?_hash=[hash:8]')
Read more comments on GitHub >

github_iconTop Results From Across the Web

vue.js - Is there a way to disable filenameHashing only for ...
Yes, there is a way. You will need to override the 'images' rule that vue-cli comes with. vue inspect --rule images yields the...
Read more >
Adding Hashes to Filenames - SurviveJS
Starting from version 5, webpack is using a deterministic way of generating filenames that's a good compromise between bundle size and long time...
Read more >
Configuration Reference | Vue CLI
If you cannot make use of the index HTML generated by Vue CLI, you can disable filename hashing by setting this option to...
Read more >
Caching - webpack
The [contenthash] substitution will add a unique hash based on the content of an ... so we don't have to deal with maintaining...
Read more >
AngularJS: How to clear query parameters in the URL?
path() + $location.hash()).replace(), but it keep the query params in the URL. I am also unable to extract the query parameters ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found