1 | <div align="center">
|
2 | <img width="200" height="200"
|
3 | src="https://cdn3.iconfinder.com/data/icons/lexter-flat-colorfull-file-formats/56/raw-256.png">
|
4 | <a href="https://github.com/webpack/webpack">
|
5 | <img width="200" height="200"
|
6 | src="https://webpack.js.org/assets/icon-square-big.svg">
|
7 | </a>
|
8 | </div>
|
9 |
|
10 | [![npm][npm]][npm-url]
|
11 | [![node][node]][node-url]
|
12 | [![deps][deps]][deps-url]
|
13 | [![tests][tests]][tests-url]
|
14 | [![coverage][cover]][cover-url]
|
15 | [![chat][chat]][chat-url]
|
16 | [![size][size]][size-url]
|
17 |
|
18 | # raw-loader
|
19 |
|
20 | A loader for webpack that allows importing files as a String.
|
21 |
|
22 | ## Getting Started
|
23 |
|
24 | To begin, you'll need to install `raw-loader`:
|
25 |
|
26 | ```console
|
27 | $ npm install raw-loader --save-dev
|
28 | ```
|
29 |
|
30 | Then add the loader to your `webpack` config. For example:
|
31 |
|
32 | **file.js**
|
33 |
|
34 | ```js
|
35 | import txt from './file.txt';
|
36 | ```
|
37 |
|
38 | **webpack.config.js**
|
39 |
|
40 | ```js
|
41 | // webpack.config.js
|
42 | module.exports = {
|
43 | module: {
|
44 | rules: [
|
45 | {
|
46 | test: /\.txt$/i,
|
47 | use: 'raw-loader',
|
48 | },
|
49 | ],
|
50 | },
|
51 | };
|
52 | ```
|
53 |
|
54 | Or from the command-line:
|
55 |
|
56 | ```console
|
57 | $ webpack --module-bind 'txt=raw-loader'
|
58 | ```
|
59 |
|
60 | And run `webpack` via your preferred method.
|
61 |
|
62 | ## Examples
|
63 |
|
64 | ### Inline
|
65 |
|
66 | ```js
|
67 | import txt from 'raw-loader!./file.txt';
|
68 | ```
|
69 |
|
70 | Beware, if you already define loader(s) for extension(s) in `webpack.config.js` you should use:
|
71 |
|
72 | ```js
|
73 | import css from '!!raw-loader!./file.css'; // Adding `!!` to a request will disable all loaders specified in the configuration
|
74 | ```
|
75 |
|
76 | ## Contributing
|
77 |
|
78 | Please take a moment to read our contributing guidelines if you haven't yet done so.
|
79 |
|
80 | [CONTRIBUTING](./.github/CONTRIBUTING.md)
|
81 |
|
82 | ## License
|
83 |
|
84 | [MIT](./LICENSE)
|
85 |
|
86 | [npm]: https://img.shields.io/npm/v/raw-loader.svg
|
87 | [npm-url]: https://npmjs.com/package/raw-loader
|
88 | [node]: https://img.shields.io/node/v/raw-loader.svg
|
89 | [node-url]: https://nodejs.org
|
90 | [deps]: https://david-dm.org/webpack-contrib/raw-loader.svg
|
91 | [deps-url]: https://david-dm.org/webpack-contrib/raw-loader
|
92 | [tests]: https://img.shields.io/circleci/project/github/webpack-contrib/raw-loader.svg
|
93 | [tests-url]: https://circleci.com/gh/webpack-contrib/raw-loader
|
94 | [cover]: https://codecov.io/gh/webpack-contrib/raw-loader/branch/master/graph/badge.svg
|
95 | [cover-url]: https://codecov.io/gh/webpack-contrib/raw-loader
|
96 | [chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
|
97 | [chat-url]: https://gitter.im/webpack/webpack
|
98 | [size]: https://packagephobia.now.sh/badge?p=raw-loader
|
99 | [size-url]: https://packagephobia.now.sh/result?p=raw-loader
|