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.

How to add versioning filehash to dynamically required files?

See original GitHub issue
  • Laravel Mix Version: 1.3.1
  • Node Version (node -v): 7.4.0
  • NPM Version (npm -v): 5.3.0
  • OS: Ubuntu 16.04

Description:

I am dynamically requiring files like so:

import(`resources/assets/images/svg/${this.name}.svg`).then((module) => {
    this.svg = module;
}).catch(error => 'An error occured while loading the svg');

These chunks are outputed to an svg directory through Webpack with the chunkFilename property:

chunkFilename: 'js/svg/[name].js'

They get properly written to my mix-manifest.json file with a query string containing a hash but is there any way to use this hash as well when creating dynamic imports? The dynamic imports functionality from webpack automatically injects your script based on a promise.

This would have to mean I would have to hook into the script that gets injected and add the query hash there somehow.

Any tips on how to get this done?

If this is not possible it would be a pretty big downer since it would mean images cannot be cachebusted when dynamically requiring them. In other words code splitting for assets can not be versioned.

Steps To Reproduce:

Use a dynamic require and enable .version().

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
bikramtuladharcommented, Feb 12, 2019

Set chunk file name that include chunkhash as below in webpack.mix.js file

mix.webpackConfig({
    .....
    output: {
        chunkFilename: '[name].js?id=[chunkhash]',
    },
});
0reactions
stale[bot]commented, Dec 4, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add versioning filehash to dynamically required files?
Use a dynamic require and enable .version() .
Read more >
How to Use the Get-FileHash PowerShell Cmdlet
Use Get-FileHash to generate a hash for a single file, an entire directory of files, or even generate hashes on streams of data...
Read more >
Understand Windows Defender Application Control (WDAC ...
Learn how WDAC policy rules and file rules can control your Windows 10 and Windows 11 computers.
Read more >
Tracking unique versions of files with hashes - Stack Overflow
One lesson I've learned toying with massive numbers of files and hashing is this: adding millions of records to a PostgreSQL database in...
Read more >
Allow to use file checksum as cache key (#18986) - GitLab.org
I use docker to cache node_modules. We need to solve problem bumping version in package.json. In docker I solved that problem by setting...
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