Skip to content

Commit

Permalink
Merge pull request #2752 from basherru/improvements/use-file-loader-i…
Browse files Browse the repository at this point in the history
…n-loaders-doc

Use file-loader instead of json-loader in loaders docs
  • Loading branch information
guilleiguaran committed Oct 5, 2020
2 parents 1a0d635 + f6f9917 commit f9c29dd
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions docs/webpack.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,36 @@ console.log(config.source_path)
## Loaders

You can add additional loaders beyond the base set that Webpacker provides by
adding it to your environment. We'll use `json-loader` as an example:
adding it to your environment. We'll use `url-loader` as an example:

```
yarn add json-loader
yarn add url-loader
```

```js
// config/webpack/environment.js
const { environment } = require('@rails/webpacker')

const jsonLoader = {
test: /\.json$/,
use: 'json-loader'
const urlLoader = {
test: /\.png$/,
use: 'url-loader'
}

// Insert json loader at the end of list
environment.loaders.append('json', jsonLoader)
// Insert url loader at the end of list
environment.loaders.append('url', urlLoader)

// Insert json loader at the top of list
environment.loaders.prepend('json', jsonLoader)
// Insert url loader at the top of list
environment.loaders.prepend('url', urlLoader)

// Insert json loader after/before a given loader
environment.loaders.insert('json', jsonLoader, { after: 'style'} )
environment.loaders.insert('json', jsonLoader, { before: 'babel'} )
// Insert url loader after/before a given loader
environment.loaders.insert('url', urlLoader, { after: 'style'} )
environment.loaders.insert('url', urlLoader, { before: 'babel'} )

module.exports = environment
```

Finally add `.json` to the list of extensions in `config/webpacker.yml`. Now if you `import()` any `.json` files inside your JavaScript
they will be processed using `json-loader`. Voila!
Finally, add `.png` to the list of extensions in `config/webpacker.yml`. Now if you `import()` any `.png` files inside your JavaScript
they will be processed using `url-loader`. Voila!

This comment has been minimized.

Copy link
@justin808

justin808 Oct 6, 2020

Contributor

@guilleiguaran Did you confirm that the default configuration of the file-loader is not used? Also, do you want to configure the backup file-loader usage?

@gauravtiwari and @jakeNiemiec I added a section on the url-loader in PR #2748,

https://github.com/rails/webpacker/pull/2748/files#diff-8f1b860532856344d5023542844a1152R164


You can also modify the loaders that Webpacker pre-configures for you. We'll update
the `babel` loader as an example:
Expand Down

0 comments on commit f9c29dd

Please sign in to comment.