Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get the entry file name in the loaders? #2090

Closed
weekeight opened this issue Feb 23, 2016 · 13 comments
Closed

How can I get the entry file name in the loaders? #2090

weekeight opened this issue Feb 23, 2016 · 13 comments

Comments

@weekeight
Copy link

If I have a entry hello.js like this:

require('./images/test.png');

and I use file-loader to handle this, then I want the built image named as "hello.test.png",how can I make it?

The following example can not fill my need:

{
  test: /\.(jpe?g|png|gif|svg)$/i,
  loaders: ['file?hash=sha512&digest=hex&name=[path][hash].[ext]']
}
@jeffijoe
Copy link

I doubt this is possible unless the file-loader lets you run arbitrary functions to format the file name.

@sokra
Copy link
Member

sokra commented Feb 24, 2016

{
  test: path.resolve("./images/test.png"),
  loader: "file?name=hello.test.png"
}

@weekeight
Copy link
Author

@sokra The project has multiple entry file,not just one.I want the built image name prefixs with its related entry file name?Can we make it?

@indieveed
Copy link

Seems duplicate to #1381.
Interested in this issue too, though.

@wojohowitz
Copy link

recursive issue references here #1381 is pointing back to this one each citing a duplicate of the other :)

@oleggromov
Copy link

Finally, guys, is there a way to get entry point name in a custom loader?

@FuriouZz
Copy link

The only way, I found was to explore the reasons of the module directly in the loader.

var findEntry = function( mod ) {
  if (mod.reasons.length > 0) {
    return findEntry( mod.reasons[0].module )
  }
  return mod.resource
}

module.exports = function MyLoader() {
  var entry = findEntry( this._module )
  ...
}

@mcm-ham
Copy link

mcm-ham commented May 19, 2017

Thanks FuriouZz, here's a small modification to make it work with HMR as well:

function findEntry(mod) {
    if (mod.reasons.length > 0 && mod.reasons[0].module.resource) {
        return findEntry(mod.reasons[0].module)
    }
    return mod.resource;
}

@webpack-bot
Copy link
Contributor

This issue had no activity for at least half a year.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@webpack-bot
Copy link
Contributor

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

@PierBJX
Copy link

PierBJX commented May 26, 2020

@mcm-ham Your solution is not working anymore. Do you have any idea?

@MuhammadMabrouk
Copy link

Any updates on this issue?!

@lishichao1002
Copy link

why this._module is undefind ?? @mcm-ham

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests