Skip to content
This repository was archived by the owner on Dec 22, 2020. It is now read-only.

Commit d57a1d5

Browse files
radubreharPatrickJS
authored andcommitted
chore(readme.md): Improve readme file (#10)
* chore(readme.md): Improve readme file * chore(readme.md): Improve loader usage description
1 parent 4ea50ec commit d57a1d5

File tree

1 file changed

+134
-9
lines changed

1 file changed

+134
-9
lines changed

README.md

Lines changed: 134 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,140 @@
1-
# json5 loader for webpack
1+
[![npm][npm]][npm-url]
2+
[![deps][deps]][deps-url]
3+
[![test][test]][test-url]
4+
[![coverage][cover]][cover-url]
5+
[![chat][chat]][chat-url]
26

3-
## Usage
7+
<div align="center">
8+
<!-- replace with accurate logo e.g from https://worldvectorlogo.com/ -->
9+
<img width="280" height="200" style=""
10+
src="https://cdn.rawgit.com/json5/json5-logo/master/json5-logo.svg">
11+
<a href="https://github.com/webpack/webpack">
12+
<img width="200" height="200" vspace="" hspace="25"
13+
src="https://worldvectorlogo.com/logos/webpack.svg">
14+
</a>
15+
<h1>JSON5 Loader</h1>
16+
<p>Webpack loader for parsing <code>json5</code> files into JavaScript objects.<p>
17+
</div>
418

5-
``` javascript
6-
var json = require("json5!./file.json5");
7-
// => returns file.json5 content as json parsed object
19+
<h2 align="center">Install</h2>
20+
21+
```sh
22+
$ npm i --save-dev json5-loader
23+
```
24+
25+
<h2 align="center">Usage</h2>
26+
27+
You can use the loader either
28+
* by configuring the `json5-loader` in the `module.loaders` object of the webpack configuration, or
29+
* by directly using the `json5!` prefix to the require statement.
30+
31+
Suppose we have the following `json5` file
32+
```js
33+
// appData.json5
34+
{
35+
env: 'production',
36+
passwordStregth: 'strong'
37+
}
38+
```
39+
40+
#### Usage with preconfigured loader
41+
42+
```js
43+
// webpack.config.js
44+
module.exports = {
45+
entry: './index.js',
46+
output: { /* ... */ },
47+
module: {
48+
loaders: [
49+
{
50+
// make all files ending in .json5 use the `json5-loader`
51+
test: /\.json5$/,
52+
loader: 'json5-loader'
53+
}
54+
]
55+
}
56+
}
57+
```
58+
59+
```js
60+
// index.js
61+
var appConfig = require('./appData.json5')
62+
// or, in ES6
63+
// import appConfig from './appData.json5'
64+
65+
console.log(appConfig.env) // 'production'
66+
```
67+
#### Usage with require statement loader prefix
68+
```js
69+
var appConfig = require("json5!./appData.json5")
70+
// returns the content as json parsed object
71+
72+
console.log(appConfig.env) // 'production'
873
```
974

10-
Don't forget to polyfill `require` if you want to use it in node.
11-
See `webpack` documentation.
75+
Don't forget to polyfill require if you want to use it in Node.js. See the webpack documentation.
76+
77+
<h2 align="center">Maintainers</h2>
78+
79+
<table>
80+
<tbody>
81+
<tr>
82+
<td align="center">
83+
<img width="150 height="150"
84+
src="https://avatars.githubusercontent.com/sokra?v=3">
85+
<br />
86+
<a href="https://github.com/">Tobias Koppers</a>
87+
</td>
88+
<td align="center">
89+
<img width="150 height="150"
90+
src="https://avatars.githubusercontent.com/gdi2290?v=3">
91+
<br />
92+
<a href="https://github.com/">PatrickJS</a>
93+
</td>
94+
<td align="center">
95+
<img width="150" height="150" src="https://avatars.githubusercontent.com/Cellule?v=3">
96+
<br />
97+
<a href="https://github.com/">Michael Ferris</a>
98+
</td>
99+
<td align="center">
100+
<img width="150" height="150"
101+
src="https://avatars.githubusercontent.com/kmck?v=3">
102+
<br />
103+
<a href="https://github.com/">Keith McKnight</a>
104+
</td>
105+
</tr>
106+
<tr>
107+
<td align="center">
108+
<img width="150" height="150"
109+
src="https://avatars.githubusercontent.com/radubrehar?v=3">
110+
<br />
111+
<a href="https://github.com/">Radu Brehar</a>
112+
</td>
113+
<td align="center">
114+
<img width="150" height="150"
115+
src="https://avatars.githubusercontent.com/kentcdodds?v=3">
116+
<br />
117+
<a href="https://github.com/">Kent C. Dodds</a>
118+
</td>
119+
<tr>
120+
<tbody>
121+
</table>
122+
123+
<h2 align="center">LICENSE</h2>
124+
125+
#### [MIT](./LICENSE)
126+
127+
[npm]: https://img.shields.io/npm/v/json-loader.svg
128+
[npm-url]: https://npmjs.com/package/json-loader
129+
130+
[deps]: https://david-dm.org/webpack/json-loader.svg
131+
[deps-url]: https://david-dm.org/webpack/json-loader
132+
133+
[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
134+
[chat-url]: https://gitter.im/webpack/webpack
12135

13-
## License
136+
[test]: http://img.shields.io/travis/webpack/json-loader.svg
137+
[test-url]: https://travis-ci.org/webpack/json-loader
14138

15-
MIT (http://www.opensource.org/licenses/mit-license.php)
139+
[cover]: https://coveralls.io/repos/github/webpack/json-loader/badge.svg?branch=master
140+
[cover-url]: https://coveralls.io/github/webpack/json-loader?branch=master

0 commit comments

Comments
 (0)