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.

Assets file name collision

See original GitHub issue

I want to open this issue again with one more case https://github.com/JeffreyWay/laravel-mix/issues/2910 We have vue components and each component can have its own assets inside the components folder.

It was a matter of time when we come to a situation when two different components have two different images with the same name. Rename images? It’s not a solution anyway.

For now, we use this temp workaround:

mix.extend('addHashToImagesFileNames', (webpackConfig) => {
  const imagesRule = webpackConfig.module.rules.find((rule) => {
    const { test } = rule;
    return test && typeof test.test === 'function' && test.test('.png');
  });

  if (!imagesRule) return;

  imagesRule.use.forEach(({ options }) => {
    if (options.name && typeof options.name === 'function') {
      options.name = (path) => {
        if (!/node_modules|bower_components/.test(path)) {
          return 'assets/images/[name].[hash:8].[ext]';
        }

        return (
          'assets/images/vendor/' +
          path
            .replace(/\\/g, '/')
            .replace(
              /((.*(node_modules|bower_components))|images|image|img|assets)\//g,
              ''
            ) +
          '?[hash]'
        );
      }
    }
  });
});
mix.addHashToImagesFileNames();

I have read the argument here https://github.com/JeffreyWay/laravel-mix/pull/2911#issuecomment-811079865 But why not do it optional? Just add addHashToFilenames option with default false value.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
thecrypticacecommented, Aug 12, 2021

I think this is something we should fix as an opt in. But I also think the only proper way to do this is to include the hash in the filename itself and not in a query string for the file in the manifest.

If we do this it’ll be in tandem with the switch to asset modules (see #3059).

0reactions
codemonkeynorthcommented, May 31, 2022

@thecrypticace does the code I noted in my reply here help?

https://github.com/laravel-mix/laravel-mix/issues/3211#issuecomment-1141640373

We had a similar issue with WPEmerge theme where assets weren’t getting copied with subfolders. It needs path.relative ideally to retain folder structure from src to dist

another implementation here for relative paths: https://github.com/webpack-contrib/file-loader/issues/261#issuecomment-576061837

Read more comments on GitHub >

github_iconTop Results From Across the Web

Assets name collision in dev mode #3786 - nuxt/nuxt.js - GitHub
Nuxt seems to copy all the images to /_nuxt/img , but doesn't add a hash of the file at the end of the...
Read more >
Conflict: Multiple assets emit to the same filename
what I want to know is what tool writes an error like "Conflict: Multiple assets emit to the same filename slots.js".
Read more >
feature request: detect resource filename collisions at compile ...
feature request: detect resource filename collisions at compile-time. Using unity 5.4.1, it's cool to have multiple "Resources" folders.
Read more >
Recommended Asset Naming Conventions
A recommended naming convention to help organize your Assets for large Unreal Engine projects.
Read more >
[AssetBundle] Collision when building ... - Unity Issue Tracker
[AssetBundle] Collision when building AssetBundles with variants if there are files with the same name · 1. Open the attached project · 2....
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