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

Assets use file-loader instead of url-loader #7061

Merged
merged 2 commits into from
Aug 7, 2018

Conversation

zauni
Copy link
Contributor

@zauni zauni commented Aug 6, 2018

Fixes #6963

@KyleAMathews
Copy link
Contributor

KyleAMathews commented Aug 6, 2018

Deploy preview for using-postcss-sass failed.

Built with commit 742b913

https://app.netlify.com/sites/using-postcss-sass/deploys/5b698275b13fb115bd788d68

@gatsbybot
Copy link
Collaborator

gatsbybot commented Aug 6, 2018

Deploy preview for gatsbygram ready!

Built with commit 742b913

https://deploy-preview-7061--gatsbygram.netlify.com

@gatsbybot
Copy link
Collaborator

Deploy preview for gatsbygram ready!

Built with commit f0f24fa

https://deploy-preview-7061--gatsbygram.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Aug 6, 2018

Deploy preview for using-drupal ready!

Built with commit 742b913

https://deploy-preview-7061--using-drupal.netlify.com

@KyleAMathews
Copy link
Contributor

KyleAMathews commented Aug 6, 2018

Deploy preview for gatsbyjs failed.

Built with commit 742b913

https://app.netlify.com/sites/gatsbyjs/deploys/5b698274b13fb115bd788d5c

@KyleAMathews
Copy link
Contributor

Thanks for jumping on this!

We don't actually want to eliminate the use of url-loader altogether. Most asset types we do want to use the url-loader for smaller assets. It's just a few types like pdf (to start with, we can add others perhaps later) that we want to switch to always using file-loader.

@zauni
Copy link
Contributor Author

zauni commented Aug 7, 2018

How about something like this:

  /**
   * Loads audio and video and inlines them via a data URI if they are below
   * the size threshold
   */
  rules.audioVideo = () => {
    return {
      use: [loaders.url()],
      test: /\.(mp4|webm|wav|mp3|m4a|aac|oga|flac)$/,
    }
  }

  /**
   * Loads assets without inlining
   */
  rules.miscAssets = () => {
    return {
      use: [loaders.file()],
      test: /\.(pdf)$/,
    }
  }

@KyleAMathews
Copy link
Contributor

Looks great! If @jquense is around, I'm sure he has thoughts too as he wrote this code.

@zauni
Copy link
Contributor Author

zauni commented Aug 7, 2018

Gatsby v1 loaded font files also with file-loader (link), whereas v2 loads it with the url-loader. Some additional insight would be nice 👍

This also reminds of this issue: facebook/create-react-app#3722

Like, it would be nice to let the user decide what he wants

import { url } from './image.png'; // file-loader
import image from './image.png'; // url-loader

But thats not solved yet :)

@KyleAMathews
Copy link
Contributor

We think GraphQL is better for letting people specify transforms :-)

I think fonts are fine leaving w/ url-loader. We have url-loader setup to only inline assets < 10kb. If a font file is < 10kb then it's probably better to inline it to speed rendering.

PDFs are different as you never want it inlined as you really only want a link so you can offer it to someone to download if they'd like so inlining is almost always a waste.

@KyleAMathews KyleAMathews merged commit f9cb6d1 into gatsbyjs:master Aug 7, 2018
@gatsbot
Copy link

gatsbot bot commented Aug 7, 2018

Holy buckets, @zauni — we just merged your PR to Gatsby! 💪💜

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (Currently we’ve got a couple t-shirts available, plus some socks that are really razzing our berries right now.)
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. You’ll receive an email shortly asking you to confirm. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again!

@KyleAMathews
Copy link
Contributor

Thanks!

@zauni
Copy link
Contributor Author

zauni commented Aug 7, 2018

Thank you very much for your fast responses!

@zauni zauni deleted the file-loader-fix branch August 7, 2018 12:14
@KyleAMathews
Copy link
Contributor

Thank you very much for fixing the problem!

porfirioribeiro pushed a commit to porfirioribeiro/gatsby that referenced this pull request Aug 22, 2018
* Assets use file-loader instead of url-loader

Fixes gatsbyjs#6963

* Just pdf files use file-loader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v2] url-loader for miscAssets? (webpack-utils.js)
3 participants