Skip to content

Commit

Permalink
Assets use file-loader instead of url-loader (gatsbyjs#7061)
Browse files Browse the repository at this point in the history
* Assets use file-loader instead of url-loader

Fixes gatsbyjs#6963

* Just pdf files use file-loader
  • Loading branch information
zauni authored and porfirioribeiro committed Aug 20, 2018
1 parent 034842d commit df3443e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/gatsby/src/utils/webpack-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ module.exports = async ({

file: (options = {}) => {
return {
loader: require.resolve(`url-loader`),
loader: require.resolve(`file-loader`),
options: {
name: `${assetRelativeRoot}[name]-[hash].[ext]`,
...options,
Expand Down Expand Up @@ -350,12 +350,23 @@ module.exports = async ({
}

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

/**
* Loads assets without inlining
*/
rules.miscAssets = () => {
return {
use: [loaders.file()],
test: /\.(mp4|webm|wav|mp3|m4a|aac|oga|flac|pdf)$/,
test: /\.pdf$/,
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ module.exports = async (
rules.yaml(),
rules.fonts(),
rules.images(),
rules.media(),
rules.miscAssets(),
]
switch (stage) {
Expand Down

0 comments on commit df3443e

Please sign in to comment.