Skip to content

Commit

Permalink
docs(assets): update code reference (#1370)
Browse files Browse the repository at this point in the history
* docs(assets): update code reference

Code reference for url-loader and file-loader was outdated and still referenced the already removed file `lib/builder/webpack/base.js` with last commit `c1e0d174319f209bbfa4d34cfd2e17e82f45537` on October 18, 2018.

I've taken the liberty to evaluate `Object.assign(this.loaders.xxx, { name: this.getFileName('xxx')})` since I think that referencing [build.js](https://github.com/nuxt/nuxt.js/blob/dev/packages/config/src/config/build.js#L15-L27) would only serve to confuse the reader.

I've also added the `file-loader` code, since the explanation above stated

> For **these two loaders**, the default configuration is:

Not sure if the intent was to show both `url-loader` and `file-loader` or `url-loader` only.

* docs(assets): add comment for 1000 bytes => 1kB

* Update content/en/guides/directory-structure/assets.md

Co-authored-by: Daniel Roe <daniel@roe.dev>

* Update content/en/guides/directory-structure/assets.md

Co-authored-by: Daniel Roe <daniel@roe.dev>

* Update content/en/guides/directory-structure/assets.md

Co-authored-by: Daniel Roe <daniel@roe.dev>

Co-authored-by: Daniel Roe <daniel@roe.dev>
  • Loading branch information
aesyondu and danielroe authored Mar 29, 2021
1 parent 3afd144 commit 303507d
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions content/en/guides/directory-structure/assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,25 +216,39 @@ The benefits of these loaders are:
For these two loaders, the default configuration is:

```js
// https://github.com/nuxt/nuxt.js/blob/dev/packages/webpack/src/config/base.js#L297-L316
;[
{
test: /\.(png|jpe?g|gif|svg|webp)$/,
// https://github.com/nuxt/nuxt.js/blob/dev/packages/webpack/src/config/base.js#L382-L411
{
test: /\.(png|jpe?g|gif|svg|webp|avif)$/i,
use: [{
loader: 'url-loader',
query: {
options: {
esModule: false,
limit: 1000, // 1kB
name: 'img/[name].[hash:7].[ext]'
name: 'img/[name].[contenthash:7].[ext]'
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
}]
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/i,
use: [{
loader: 'url-loader',
query: {
limit: 1000, // 1kB
name: 'fonts/[name].[hash:7].[ext]'
options: {
esModule: false,
limit: 1000, // 1kB
name: 'fonts/[name].[contenthash:7].[ext]'
}
}]
},
{
test: /\.(webm|mp4|ogv)$/i,
use: [{
loader: 'file-loader',
options: {
esModule: false,
name: 'videos/[name].[contenthash:7].[ext]'
}
}
]
}]
}
```

Which means that every file below 1 kB will be inlined as base64 data URL. Otherwise, the image/font will be copied in its corresponding folder (inside the `.nuxt` directory) with a name containing a version hash for better caching.
Expand Down

0 comments on commit 303507d

Please sign in to comment.