webpackurlloader

Webpack url-loader set destination path


I'm using webpack's url-loader plugin and have it configured as:

{
    test: /\.(ttf|eot|woff|woff2|svg)$/,
    loader: "url-loader?limit=50000"
}

It output files > 50k to the file system, but I can't find how to set a destination path.

In this case, I want the files to be stored to ./fonts and not the root.


Solution

  • url-loader is build on file-loader, so you can use it like file-loader, as shown below:

    {
        test: /\.(ttf|eot|woff|woff2|svg)$/,
        loader: "url-loader?limit=50000&name=fonts/[name].[ext]"
    }