shaketbaby / directory-named-webpack-plugin

A Webpack plugin that treats a file with the name of directory as the index file
MIT License
182 stars 17 forks source link

Doesn't resolve when using HMR #34

Open fadilmamedov opened 5 years ago

fadilmamedov commented 5 years ago

Let's say I have a folder in source folder named Component and two files inside it: index.js and Component.js. Configuration looks like so:

extensions: ['*', '.js', '.jsx', '.json'],
plugins: [
  new DirectoryNamedWebpackPlugin(true),
],

When I start Webpack everything works as expected, index.js file is loaded. But when I remove index.js file I expect Component.js to be loaded, but instead it still tries to load index.js file. It works as expected if I restart Webpack though. But I want this to be working correctly with Webpack Dev Server and HMR.

What am I doing wrong?

fadilmamedov commented 5 years ago

Any updates on this?

shaketbaby commented 5 years ago

Sorry, somehow I missed this.

From what I understand, I think this is an issue of Webpack. I feel Webpack caches the resolved path for a given import path and doesn't use the resolver to resolve the path again with HMR.

catamphetamine commented 4 years ago

From what I understand, I think this is an issue of Webpack. I feel Webpack caches the resolved path for a given import path and doesn't use the resolver to resolve the path again with HMR.

Perhaps something as simple as delete require.cache[path]. Just an idea, we're not having the issue.

shaketbaby commented 4 years ago

Thanks for the idea. Actual require call is done by Webpack, this plugin only tells Webpack which file should be loaded for a given import/require. I didn't check the source code of Webpack but I suspect it probably is not using require as Node interpret things as JavaScript, but Webpack supports loading all kinds of things.