Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

fallback loader options #118

Closed
ghost opened this issue Mar 4, 2018 · 11 comments · Fixed by #126 or JetBrains/ring-ui#359 · May be fixed by kogg/kogg.github.io#8
Closed

fallback loader options #118

ghost opened this issue Mar 4, 2018 · 11 comments · Fixed by #126 or JetBrains/ring-ui#359 · May be fixed by kogg/kogg.github.io#8

Comments

@ghost
Copy link

ghost commented Mar 4, 2018

Make it possible to add options to the fallback loader

e.g.

{
  test: /\.(woff|woff2|eot|ttf|svg)$/,
  use: {
    loader: "url-loader",
    options: {
      limit: 8192,
      fallback: {
        loader: "file-loader",
        options: {
          name: isProd ? "[hash:7].[ext]" : "[name].[ext]",
          publicPath: "/fonts",
          outputPath: "fonts"
        }
      }
    }
  }
}
@alexander-akait
Copy link
Member

@Sparki2002 PR welcome 👍

@fengcen
Copy link

fengcen commented Mar 11, 2018

I want this feature too.

@TimHolzherr
Copy link
Contributor

This feature would be really nice.
Does anybody know a workaround? E.g. somehow wrapping file-loader with predefined options or something similar?

@fengcen
Copy link

fengcen commented Mar 12, 2018

@Sparki2002 I found that you can set any fallback options like this:

{
  test: /\.(woff|woff2|eot|ttf|svg)$/,
  use: {
    loader: "url-loader",
    options: {
      limit: 8192,
      fallback: "file-loader",
      
      // Below are the fallback options
      name: isProd ? "[hash:7].[ext]" : "[name].[ext]",
      publicPath: "/fonts",
      outputPath: "fonts"
    }
  }
}

@TimHolzherr
Copy link
Contributor

Works great, thanks @fengcen!

@evilebottnawi: I think adding this to the readme would be helpful for future users.

@queses
Copy link

queses commented Mar 29, 2018

I believe, that also it would be good to have feature to chain fallback loaders.
Usage example:

  • I want my small pictures to be loaded as url-string
  • I want my bigger pictures to be optimized

So I need this code:

...
test: /\.(gif|png|jpe?g)$/,
  loader: 'url-loader'
  options: {
     limit: 1000,
     fallback: [
       'file-loader',
       {
         loader: 'image-webpack-loader'
         options: {
           // ...optimizing options
         }
       }
     ]
   }
}

@alexander-akait
Copy link
Member

@queses no, please read how works loaders

@alexander-akait
Copy link
Member

@fengcen @TimHolzherr yep, feel free to send PR

shellscape pushed a commit that referenced this issue Jun 16, 2018
Resolves #118

It is now possible to explicitly specify options for the fallback loader.

The new definition (schema) for the fallback option is a lighter variant of the one for module.rules.use. See schemas/WebpackOptions.json in the webpack repository.
@damianobarbati
Copy link

damianobarbati commented Aug 14, 2018

Hey @evilebottnawi watch out: I don't see the default fallback=file-loader to be respected, just lost 1 hour on this to find out I had to explicitly set it like this (I'm on url-loader@1.1.0):

{
    test: /\.(woff|woff2|ttf|eot)$/i,
    use: [{
        loader: 'url-loader',
        options: {
            limit: 8192,
            fallback: 'file-loader',
            outputPath: '/assets/fonts',
            name: '[name].[ext]?hash=[hash]',
        },
    }],
}

@alexander-akait
Copy link
Member

@damianobarbati can you create new issue with minimum reproducible test repo?

@xiaotiandada
Copy link

good

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.