Code Monkey home page Code Monkey logo

Comments (7)

danahartweg avatar danahartweg commented on June 30, 2024 2

Was looking through this today, and it did have me stumped initially as well. What you have to do is supply an additional param of regExp on the query string with the regex you want to match against the source file path.

In my case, my source path is something like src/moduleName/images/image.png, and my build directory is build/modules/moduleName. To have the file loader place the images in build/modules/moduleName/images, the regex and naming I used is: regExp=src\/(.+?)\/&name=[1]/images/[hash].[ext].

The regex isn't perfect, but without spending hours on it, I was unable to generate a matcher that would extract all groups between slashes that started after a particular string.

Anyway, hope this helps someone place files in a subdirectory inside their module entry point!

from file-loader.

pixeldrew avatar pixeldrew commented on June 30, 2024 2

After just stumbling with this myself.

You want to use the regExp option, it doesn't use the regExp from the test. [0] in regex is the whole capture, you want the second capture [2].

The regex your using is a little greedy, imagine the name of your import is 'img/animage.jpg'. The regex will get 'img/animage'

The name templage [2]/img/[name].[ext] would then output the file as img/animage/img/animage.jpg

from file-loader.

Benno007 avatar Benno007 commented on June 30, 2024 1

That didn't work for me... trying to get the query string applied in the file for cache busting icon fonts. Just kept coming out as font.eot?[1] :(

Does url-loader not have it maybe?

{
                test: /\.(eot|ttf|woff|woff2|svg)/i,
                loader: 'url-loader?regExp=\\.[ext]\\?(.+)&limit=1&name=assets/[name].[ext]?[1]
}

from file-loader.

anselmdk avatar anselmdk commented on June 30, 2024

I don't think this is currently supported, I think the readme is taken from https://github.com/webpack/loader-utils

I'd love for this to work as well, as I'd like to place images in sub directories.

from file-loader.

shri3k avatar shri3k commented on June 30, 2024

@Benno007 don't think url-loader has this option yet. I'd be happy to be proven wrong though.

from file-loader.

alexander-akait avatar alexander-akait commented on June 30, 2024

@pixeldrew @leonardoanalista @danahartweg we can implement customInterpolateName from https://github.com/webpack/loader-utils/blob/ddf64e49c5871c7229a5a536656a711479c08516/lib/interpolateName.js#L89 and it is allow to using custom function to set name. Will it help to solve your problem?

from file-loader.

pixeldrew avatar pixeldrew commented on June 30, 2024

I can't see how having that option would hurt. I was able to fix my issue, perhaps some clearer documentation would also help.

from file-loader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.