Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 517
user3900456 Avatar asked Dec 05 '15 20:12

user3900456


2 Answers

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]"
}
like image 54
wandergis Avatar answered Oct 12 '22 21:10

wandergis


you can write it like this

{
        test: /\.(png|woff|eot|ttf|svg|gif)$/,
        use: [
          {
          loader: 'url-loader',
          options: {
            limit: 10000, // if less than 10 kb, add base64 encoded image to css
            name: "assets/[hash].[ext]" // if more than 10 kb move to this folder in build using file-loader
          }
        }]
      }
like image 13
Johansrk Avatar answered Oct 12 '22 21:10

Johansrk