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

Commit 9dbd867

Browse files
michael-ciniawskyjoshwiens
authored andcommitted
docs(README): standardize (#61)
1 parent a2ddc3e commit 9dbd867

1 file changed

Lines changed: 142 additions & 58 deletions

File tree

README.md

Lines changed: 142 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
[![npm][npm]][npm-url]
2+
[![node][node]][node-url]
23
[![deps][deps]][deps-url]
4+
[![tests][tests]][tests-url]
5+
[![coverage][cover]][cover-url]
36
[![chat][chat]][chat-url]
47

58
<div align="center">
6-
<!-- replace with accurate logo e.g from https://worldvectorlogo.com/ -->
79
<a href="https://github.com/webpack/webpack">
8-
<img width="200" height="200" vspace="" hspace="25"
10+
<img width="200" height="200"
911
src="https://cdn.rawgit.com/webpack/media/e7485eb2/logo/icon.svg">
1012
</a>
1113
<h1>Bundle Loader</h1>
12-
<p>Bundle loader for webpack.<p>
14+
<p>Bundle loader for webpack<p>
1315
</div>
1416

1517
<h2 align="center">Install</h2>
@@ -20,94 +22,167 @@ npm i bundle-loader --save
2022

2123
<h2 align="center"><a href="https://webpack.js.org/concepts/loaders">Usage</a></h2>
2224

23-
``` javascript
24-
// The chunk is requested, when you require the bundle
25-
var waitForChunk = require("bundle-loader!./file.js");
25+
**webpack.config.js**
26+
```js
27+
module.exports = {
28+
module: {
29+
rules: [
30+
{
31+
test: /\.bundle\.js$/,
32+
use: 'bundle-loader'
33+
}
34+
]
35+
}
36+
}
37+
```
38+
39+
The chunk is requested, when you require the bundle.
40+
41+
**file.js**
42+
```js
43+
import bundle from './file.bundle.js';
44+
```
45+
46+
To wait until the chunk is available (and get the exports)
47+
you need to async wait for it.
2648

27-
// To wait until the chunk is available (and get the exports)
28-
// you need to async wait for it.
29-
waitForChunk(function(file) {
30-
// use file like it was required with
31-
// var file = require("./file.js");
49+
```js
50+
bundle((file) => {
51+
// use the file like it was required
52+
const file = require('./file.js')
3253
});
33-
// wraps the require in a require.ensure block
54+
```
55+
56+
This wraps the `require('file.js')` in a `require.ensure` block
3457

35-
// Multiple callbacks can be added. They will be executed in the order of addition.
36-
waitForChunk(callbackTwo);
37-
waitForChunk(callbackThree);
38-
// If a callback is added after dependencies were loaded, it will be called immediately.
58+
Multiple callbacks can be added. They will be executed in the order of addition.
59+
60+
```js
61+
bundle(callbackTwo)
62+
bundle(callbackThree)
3963
```
4064

41-
The file is requested when you require the bundle loader. If you want it to request it lazy, use:
65+
If a callback is added after dependencies were loaded, it will be called immediately.
4266

43-
``` javascript
44-
var load = require("bundle-loader?lazy!./file.js");
67+
<h2 align="center">Options</h2>
4568

46-
// The chunk is not requested until you call the load function
47-
load(function(file) {
69+
|Name|Type|Default|Description|
70+
|:--:|:--:|:-----:|:----------|
71+
|**`lazy`**|`{Boolean}`|`false`|Loads the imported bundle asynchronously|
72+
|**`name`**|`{String}`|`[id].[name]`|Configure a custom filename for your imported bundle|
4873

49-
});
74+
### `lazy`
75+
76+
The file is requested when you require the `bundle-loader`. If you want it to request it lazy, use:
77+
78+
**webpack.config.js**
79+
```js
80+
{
81+
loader: 'bundle-loader',
82+
options: {
83+
lazy: true
84+
}
85+
}
5086
```
51-
### `name` query parameter
5287

53-
You may set name for a bundle using the `name` query parameter.
88+
```js
89+
import bundle from './file.bundle.js'
90+
91+
bundle((file) => {...})
92+
```
93+
94+
> ℹ️ The chunk is not requested until you call the load function
95+
96+
### `name`
97+
98+
You may set name for a bundle using the `name` options parameter.
5499
See [documentation](https://github.com/webpack/loader-utils#interpolatename).
55100

56-
**Note** chunks created by the loader will be named according to the
57-
[`output.chunkFilename`](https://webpack.js.org/configuration/output/#output-chunkfilename) rule, which defaults to `[id].[name]`.
58-
Here `[name]` corresponds to the chunk name set in the `name` query parameter.
101+
**webpack.config.js**
102+
```js
103+
{
104+
loader: 'bundle-loader',
105+
options: {
106+
name: '[name]'
107+
}
108+
}
109+
```
110+
111+
> :warning: chunks created by the loader will be named according to the
112+
[`output.chunkFilename`](https://webpack.js.org/configuration/output/#output-chunkfilename) rule, which defaults to `[id].[name]`. Here `[name]` corresponds to the chunk name set in the `name` options parameter.
59113

60-
#### Example:
114+
<h2 align="center">Examples</h2>
61115

62-
``` js
63-
require("bundle-loader?lazy&name=my-chunk!./file.js");
64-
require("bundle-loader?lazy&name=[name]!./file.js");
116+
```js
117+
import bundle from './file.bundle.js'
65118
```
66-
And the webpack configuration:
119+
120+
**webpack.config.js**
67121
``` js
68122
module.exports = {
69-
entry: { ... },
70-
output : {
71-
path : ...,
72-
filename : '[name].js',
73-
chunkFilename : '[name]-[id].js', // or whatever other format you want.
74-
},
123+
entry: {
124+
index: './App.js'
125+
},
126+
output: {
127+
path: path.resolve(__dirname, 'dest'),
128+
filename: '[name].js',
129+
// or whatever other format you want
130+
chunkFilename: '[name].[id].js',
131+
},
132+
module: {
133+
rules: [
134+
{
135+
test: /\.bundle\.js$/,
136+
use: {
137+
loader: 'bundle-loader'
138+
options: {
139+
name: 'my-chunk'
140+
}
141+
}
142+
}
143+
]
144+
}
75145
}
76146
```
77147

78-
Normal chunks will show up using the `filename` rule above, and be named according to their chunkname.
79-
Chunks from `bundle-loader`, however will load using the `chunkFilename` rule, so the example files will produce `my-chunk-1.js` and `file-2.js` respectively.
148+
Normal chunks will show up using the `filename` rule above, and be named according to their `[chunkname]`.
149+
150+
Chunks from `bundle-loader`, however will load using the `chunkFilename` rule, so the example files will produce `my-chunk.1.js` and `file-2.js` respectively.
80151

81-
You can also use `chunkFilename` to add hash values to the filename, since putting `[hash]` in the bundle query parameter does not work correctly.
152+
You can also use `chunkFilename` to add hash values to the filename, since putting `[hash]` in the bundle options parameter does not work correctly.
82153

83154
<h2 align="center">Maintainers</h2>
84155

85156
<table>
86157
<tbody>
87158
<tr>
88159
<td align="center">
89-
<img width="150" height="150"
90-
src="https://avatars3.githubusercontent.com/u/166921?v=3&s=150">
91-
</br>
92-
<a href="https://github.com/bebraw">Juho Vepsäläinen</a>
160+
<a href="https://github.com/bebraw">
161+
<img width="150" height="150" src="https://github.com/bebraw.png?v=3&s=150">
162+
</br>
163+
Juho Vepsäläinen
164+
</a>
93165
</td>
94166
<td align="center">
95-
<img width="150" height="150"
96-
src="https://avatars2.githubusercontent.com/u/8420490?v=3&s=150">
97-
</br>
98-
<a href="https://github.com/d3viant0ne">Joshua Wiens</a>
167+
<a href="https://github.com/d3viant0ne">
168+
<img width="150" height="150" src="https://github.com/d3viant0ne.png?v=3&s=150">
169+
</br>
170+
Joshua Wiens
171+
</a>
99172
</td>
100173
<td align="center">
101-
<img width="150" height="150"
102-
src="https://avatars3.githubusercontent.com/u/533616?v=3&s=150">
103-
</br>
104-
<a href="https://github.com/SpaceK33z">Kees Kluskens</a>
174+
<a href="https://github.com/michael-ciniawsky">
175+
<img width="150" height="150" src="https://github.com/michael-ciniawsky.png?v=3&s=150">
176+
</br>
177+
Michael Ciniawsky
178+
</a>
105179
</td>
106180
<td align="center">
107-
<img width="150" height="150"
108-
src="https://avatars3.githubusercontent.com/u/3408176?v=3&s=150">
109-
</br>
110-
<a href="https://github.com/TheLarkInn">Sean Larkin</a>
181+
<a href="https://github.com/evilebottnawi">
182+
<img width="150" height="150" src="https://github.com/evilebottnawi.png?v=3&s=150">
183+
</br>
184+
Alexander Krasnoyarov
185+
</a>
111186
</td>
112187
</tr>
113188
<tbody>
@@ -117,8 +192,17 @@ You can also use `chunkFilename` to add hash values to the filename, since putti
117192
[npm]: https://img.shields.io/npm/v/bundle-loader.svg
118193
[npm-url]: https://npmjs.com/package/bundle-loader
119194

195+
[node]: https://img.shields.io/node/v/bundle-loader.svg
196+
[node-url]: https://nodejs.org
197+
120198
[deps]: https://david-dm.org/webpack-contrib/bundle-loader.svg
121199
[deps-url]: https://david-dm.org/webpack-contrib/bundle-loader
122200

123-
[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
201+
[tests]: http://img.shields.io/travis/webpack-contrib/bundle-loader.svg
202+
[tests-url]: https://travis-ci.org/webpack-contrib/bundle-loader
203+
204+
[cover]: https://coveralls.io/repos/github/webpack-contrib/bundle-loader/badge.svg
205+
[cover-url]: https://coveralls.io/github/webpack-contrib/bundle-loader
206+
207+
[chat]: https://badges.gitter.im/webpack/webpack.svg
124208
[chat-url]: https://gitter.im/webpack/webpack

0 commit comments

Comments
 (0)