|
1 |
| -[![npm][npm]][npm-url] |
2 |
| -[![node][node]][node-url] |
3 |
| -[![deps][deps]][deps-url] |
4 |
| -[![tests][tests]][tests-url] |
5 |
| -[![coverage][cover]][cover-url] |
6 |
| -[![chat][chat]][chat-url] |
7 |
| - |
8 |
| -<div align="center"> |
9 |
| - <a href="https://github.com/webpack/webpack"> |
10 |
| - <img width="200" height="200" |
11 |
| - src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon.svg"> |
12 |
| - </a> |
13 |
| - <h1>URL Loader</h1> |
14 |
| - <p>Loads files as `base64` encoded URL</p> |
15 |
| -</div> |
16 |
| - |
17 |
| -<h2 align="center">Install</h2> |
18 |
| - |
19 |
| -```bash |
20 |
| -npm install --save-dev url-loader |
21 |
| -``` |
22 |
| - |
23 |
| -<h2 align="center"><a href="https://webpack.js.org/concepts/loaders">Usage</a></h2> |
24 |
| - |
25 |
| -The `url-loader` works like the [`file-loader`](https://github.com/webpack-contrib/file-loader), but can return a DataURL if the file is smaller than a byte limit. |
26 |
| - |
27 |
| - |
28 |
| -```js |
29 |
| -import img from './image.png' |
30 |
| -``` |
31 |
| - |
32 |
| -**webpack.config.js** |
33 |
| -```js |
34 |
| -module.exports = { |
35 |
| - module: { |
36 |
| - rules: [ |
37 |
| - { |
38 |
| - test: /\.(png|jpg|gif)$/, |
39 |
| - use: [ |
40 |
| - { |
41 |
| - loader: 'url-loader', |
42 |
| - options: { |
43 |
| - limit: 8192 |
44 |
| - } |
45 |
| - } |
46 |
| - ] |
47 |
| - } |
48 |
| - ] |
49 |
| - } |
50 |
| -} |
51 |
| -``` |
52 |
| - |
53 |
| -<h2 align="center">Options</h2> |
54 |
| - |
55 |
| -|Name|Type|Default|Description| |
56 |
| -|:--:|:--:|:-----:|:----------| |
57 |
| -|**[`limit`](#limit)**|`{Number}`|`undefined`|Byte limit to inline files as Data URL| |
58 |
| -|**[`mimetype`](#mimetype)**|`{String}`|`extname`|Specify MIME type for the file (Otherwise it's inferred from the file extension)| |
59 |
| -|**[`fallback`](#fallback)**|`{String}`|`file-loader`|Specify `loader` for the file when file is greater than the limit (in bytes)| |
60 |
| - |
61 |
| -### `limit` |
62 |
| - |
63 |
| -If the file is greater than the limit (in bytes) the [`file-loader`](https://github.com/webpack-contrib/file-loader) is used by default and all query parameters are passed to it. |
64 |
| -You can use other loader using `fallback` option. |
65 |
| - |
66 |
| -The limit can be specified via loader options and defaults to no limit. |
67 |
| - |
68 |
| -**webpack.config.js** |
69 |
| -```js |
70 |
| -{ |
71 |
| - loader: 'url-loader', |
72 |
| - options: { |
73 |
| - limit: 8192 |
74 |
| - } |
75 |
| -} |
76 |
| -``` |
77 |
| - |
78 |
| -### `mimetype` |
79 |
| - |
80 |
| -Set the MIME type for the file. If unspecified the file extensions will be used to lookup the MIME type. |
81 |
| - |
82 |
| -**webpack.config.js** |
83 |
| -```js |
84 |
| -{ |
85 |
| - loader: 'url-loader', |
86 |
| - options: { |
87 |
| - mimetype: 'image/png' |
88 |
| - } |
89 |
| -} |
90 |
| -``` |
91 |
| - |
92 |
| -### `fallback` |
93 |
| - |
94 |
| -**webpack.config.js** |
95 |
| -```js |
96 |
| -{ |
97 |
| - loader: 'url-loader', |
98 |
| - options: { |
99 |
| - fallback: 'responsive-loader' |
100 |
| - } |
101 |
| -} |
102 |
| -``` |
103 |
| - |
104 |
| -<h2 align="center">Maintainers</h2> |
105 |
| - |
106 |
| -<table> |
107 |
| - <tbody> |
108 |
| - <tr> |
109 |
| - <td align="center"> |
110 |
| - <a href="https://github.com/bebraw"> |
111 |
| - <img width="150" height="150" src="https://github.com/bebraw.png?v=3&s=150"> |
112 |
| - </br> |
113 |
| - Juho Vepsäläinen |
114 |
| - </a> |
115 |
| - </td> |
116 |
| - <td align="center"> |
117 |
| - <a href="https://github.com/d3viant0ne"> |
118 |
| - <img width="150" height="150" src="https://github.com/d3viant0ne.png?v=3&s=150"> |
119 |
| - </br> |
120 |
| - Joshua Wiens |
121 |
| - </a> |
122 |
| - </td> |
123 |
| - <td align="center"> |
124 |
| - <a href="https://github.com/sapegin"> |
125 |
| - <img width="150" height="150" src="https://github.com/sapegin.png?v=3&s=150"> |
126 |
| - </br> |
127 |
| - Artem Sapegin |
128 |
| - </a> |
129 |
| - </td> |
130 |
| - <td align="center"> |
131 |
| - <a href="https://github.com/michael-ciniawsky"> |
132 |
| - <img width="150" height="150" src="https://github.com/michael-ciniawsky.png?v=3&s=150"> |
133 |
| - </br> |
134 |
| - Michael Ciniawsky |
135 |
| - </a> |
136 |
| - </td> |
137 |
| - <td align="center"> |
138 |
| - <a href="https://github.com/evilebottnawi"> |
139 |
| - <img width="150" height="150" src="https://github.com/evilebottnawi.png?v=3&s=150"> |
140 |
| - </br> |
141 |
| - Alexander Krasnoyarov |
142 |
| - </a> |
143 |
| - </td> |
144 |
| - </tr> |
145 |
| - <tbody> |
146 |
| -</table> |
147 |
| - |
148 |
| - |
149 |
| -[npm]: https://img.shields.io/npm/v/url-loader.svg |
150 |
| -[npm-url]: https://npmjs.com/package/url-loader |
151 |
| - |
152 |
| -[node]: https://img.shields.io/node/v/url-loader.svg |
153 |
| -[node-url]: https://nodejs.org |
154 |
| - |
155 |
| -[deps]: https://david-dm.org/webpack-contrib/url-loader.svg |
156 |
| -[deps-url]: https://david-dm.org/webpack-contrib/url-loader |
157 |
| - |
158 |
| -[tests]: http://img.shields.io/travis/webpack-contrib/url-loader.svg |
159 |
| -[tests-url]: https://travis-ci.org/webpack-contrib/url-loader |
160 |
| - |
161 |
| -[cover]: https://coveralls.io/repos/github/webpack-contrib/url-loader/badge.svg |
162 |
| -[cover-url]: https://coveralls.io/github/webpack-contrib/url-loader |
163 |
| - |
164 |
| -[chat]: https://badges.gitter.im/webpack/webpack.svg |
165 |
| -[chat-url]: https://gitter.im/webpack/webpack |
| 1 | +[![npm][npm]][npm-url] |
| 2 | +[![node][node]][node-url] |
| 3 | +[![deps][deps]][deps-url] |
| 4 | +[![tests][tests]][tests-url] |
| 5 | +[![coverage][cover]][cover-url] |
| 6 | +[![chat][chat]][chat-url] |
| 7 | + |
| 8 | +<div align="center"> |
| 9 | + <a href="https://github.com/webpack/webpack"> |
| 10 | + <img width="200" height="200" |
| 11 | + src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon.svg"> |
| 12 | + </a> |
| 13 | + <h1>URL Loader</h1> |
| 14 | + <p>Loads files as `base64` encoded URL</p> |
| 15 | +</div> |
| 16 | + |
| 17 | +<h2 align="center">Install</h2> |
| 18 | + |
| 19 | +```bash |
| 20 | +npm install --save-dev url-loader |
| 21 | +``` |
| 22 | + |
| 23 | +<h2 align="center"><a href="https://webpack.js.org/concepts/loaders">Usage</a></h2> |
| 24 | + |
| 25 | +The `url-loader` works like the [`file-loader`](https://github.com/webpack-contrib/file-loader), but can return a DataURL if the file is smaller than a byte limit. |
| 26 | + |
| 27 | + |
| 28 | +```js |
| 29 | +import img from './image.png' |
| 30 | +``` |
| 31 | + |
| 32 | +**webpack.config.js** |
| 33 | +```js |
| 34 | +module.exports = { |
| 35 | + module: { |
| 36 | + rules: [ |
| 37 | + { |
| 38 | + test: /\.(png|jpg|gif)$/, |
| 39 | + use: [ |
| 40 | + { |
| 41 | + loader: 'url-loader', |
| 42 | + options: { |
| 43 | + limit: 8192 |
| 44 | + } |
| 45 | + } |
| 46 | + ] |
| 47 | + } |
| 48 | + ] |
| 49 | + } |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +<h2 align="center">Options</h2> |
| 54 | + |
| 55 | +|Name|Type|Default|Description| |
| 56 | +|:--:|:--:|:-----:|:----------| |
| 57 | +|**[`limit`](#limit)**|`{Number}`|`undefined`|Byte limit to inline files as Data URL| |
| 58 | +|**[`mimetype`](#mimetype)**|`{String}`|`extname`|Specify MIME type for the file (Otherwise it's inferred from the file extension)| |
| 59 | +|**[`fallback`](#fallback)**|`{String}`|`file-loader`|Specify `loader` for the file when file is greater than the limit (in bytes)| |
| 60 | + |
| 61 | +### `limit` |
| 62 | + |
| 63 | +If the file is greater than the limit (in bytes) the [`file-loader`](https://github.com/webpack-contrib/file-loader) is used by default and all query parameters are passed to it. |
| 64 | +You can use other loader using `fallback` option. |
| 65 | + |
| 66 | +The limit can be specified via loader options and defaults to no limit. |
| 67 | + |
| 68 | +**webpack.config.js** |
| 69 | +```js |
| 70 | +{ |
| 71 | + loader: 'url-loader', |
| 72 | + options: { |
| 73 | + limit: 8192 |
| 74 | + } |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +### `mimetype` |
| 79 | + |
| 80 | +Set the MIME type for the file. If unspecified the file extensions will be used to lookup the MIME type. |
| 81 | + |
| 82 | +**webpack.config.js** |
| 83 | +```js |
| 84 | +{ |
| 85 | + loader: 'url-loader', |
| 86 | + options: { |
| 87 | + mimetype: 'image/png' |
| 88 | + } |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +### `fallback` |
| 93 | + |
| 94 | +**webpack.config.js** |
| 95 | +```js |
| 96 | +{ |
| 97 | + loader: 'url-loader', |
| 98 | + options: { |
| 99 | + fallback: 'responsive-loader' |
| 100 | + } |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +<h2 align="center">Maintainers</h2> |
| 105 | + |
| 106 | +<table> |
| 107 | + <tbody> |
| 108 | + <tr> |
| 109 | + <td align="center"> |
| 110 | + <a href="https://github.com/bebraw"> |
| 111 | + <img width="150" height="150" src="https://github.com/bebraw.png?v=3&s=150"> |
| 112 | + </br> |
| 113 | + Juho Vepsäläinen |
| 114 | + </a> |
| 115 | + </td> |
| 116 | + <td align="center"> |
| 117 | + <a href="https://github.com/d3viant0ne"> |
| 118 | + <img width="150" height="150" src="https://github.com/d3viant0ne.png?v=3&s=150"> |
| 119 | + </br> |
| 120 | + Joshua Wiens |
| 121 | + </a> |
| 122 | + </td> |
| 123 | + <td align="center"> |
| 124 | + <a href="https://github.com/sapegin"> |
| 125 | + <img width="150" height="150" src="https://github.com/sapegin.png?v=3&s=150"> |
| 126 | + </br> |
| 127 | + Artem Sapegin |
| 128 | + </a> |
| 129 | + </td> |
| 130 | + <td align="center"> |
| 131 | + <a href="https://github.com/michael-ciniawsky"> |
| 132 | + <img width="150" height="150" src="https://github.com/michael-ciniawsky.png?v=3&s=150"> |
| 133 | + </br> |
| 134 | + Michael Ciniawsky |
| 135 | + </a> |
| 136 | + </td> |
| 137 | + <td align="center"> |
| 138 | + <a href="https://github.com/evilebottnawi"> |
| 139 | + <img width="150" height="150" src="https://github.com/evilebottnawi.png?v=3&s=150"> |
| 140 | + </br> |
| 141 | + Alexander Krasnoyarov |
| 142 | + </a> |
| 143 | + </td> |
| 144 | + </tr> |
| 145 | + <tbody> |
| 146 | +</table> |
| 147 | + |
| 148 | + |
| 149 | +[npm]: https://img.shields.io/npm/v/url-loader.svg |
| 150 | +[npm-url]: https://npmjs.com/package/url-loader |
| 151 | + |
| 152 | +[node]: https://img.shields.io/node/v/url-loader.svg |
| 153 | +[node-url]: https://nodejs.org |
| 154 | + |
| 155 | +[deps]: https://david-dm.org/webpack-contrib/url-loader.svg |
| 156 | +[deps-url]: https://david-dm.org/webpack-contrib/url-loader |
| 157 | + |
| 158 | +[tests]: https://circleci.com/gh/webpack-contrib/url-loader/tree/master.svg?style=svg |
| 159 | +[tests-url]: https://circleci.com/gh/webpack-contrib/url-loader/tree/master |
| 160 | + |
| 161 | +[cover]: https://coveralls.io/repos/github/webpack-contrib/url-loader/badge.svg |
| 162 | +[cover-url]: https://coveralls.io/github/webpack-contrib/url-loader |
| 163 | + |
| 164 | +[chat]: https://badges.gitter.im/webpack/webpack.svg |
| 165 | +[chat-url]: https://gitter.im/webpack/webpack |
0 commit comments