Skip to content

Commit 74e4787

Browse files
vlad-zhukovAndy Wermke
authored and
Andy Wermke
committed
Format markdown files with Prettier (#281)
* Format markdown files with Prettier * Fix various style issues * Fix one more case
1 parent 3609b74 commit 74e4787

31 files changed

+621
-421
lines changed

CONTRIBUTING.md

+17-22
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,30 @@ yarn test
1616

1717
## Code
1818

19-
This repository is a monorepo which means it contains multiple NPM
20-
packages. We use [Yarn workspaces](https://yarnpkg.com/en/docs/workspaces)
21-
architecture to install dependencies and link local packages between
22-
each other, and [`lerna`](https://github.com/lerna/lerna) to run
19+
This repository is a monorepo which means it contains multiple NPM packages. We use
20+
[Yarn workspaces](https://yarnpkg.com/en/docs/workspaces) architecture to install dependencies and
21+
link local packages between each other, and [`lerna`](https://github.com/lerna/lerna) to run
2322
commands for one or more packages from the root directory.
2423

25-
Running `yarn install` in the repository's root directory will install
26-
the dependencies of all packages and link the packages that depend on
27-
each other.
24+
Running `yarn install` in the repository's root directory will install the dependencies of all
25+
packages and link the packages that depend on each other.
2826

29-
Running `yarn test` will run all packages' tests. Run `yarn test`
30-
inside a package directory to test this package only.
27+
Running `yarn test` will run all packages' tests. Run `yarn test` inside a package directory to test
28+
this package only.
3129

32-
Just edit the code like you always do. Be aware that we automatically
33-
lint and format code with [eslint](https://eslint.org/) and
34-
[prettier](https://prettier.io/).
30+
Just edit the code like you always do. Be aware that we automatically lint and format code with
31+
[eslint](https://eslint.org/) and [prettier](https://prettier.io/).
3532

3633
## Share
3734

38-
1. Fork the repository.
39-
2. Create a new branch from `master`.
40-
3. Do something awesome.
41-
4. Add / update tests.
42-
5. Update changelogs of all packages that you change. Use *Next release*
43-
as a version number.
44-
6. Push them and open a pull request.
45-
35+
1. Fork the repository.
36+
2. Create a new branch from `master`.
37+
3. Do something awesome.
38+
4. Add / update tests.
39+
5. Update changelogs of all packages that you change. Use _Next release_ as a version number.
40+
6. Push them and open a pull request.
4641

4742
## More Information
4843

49-
* [How to Test Blocks](docs/TESTING.md)
50-
* [How to Write a Webpack Block](docs/BLOCK-CREATION.md)
44+
- [How to Test Blocks](docs/TESTING.md)
45+
- [How to Write a Webpack Block](docs/BLOCK-CREATION.md)

README.md

+100-71
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
[![Build Status](https://travis-ci.org/andywer/webpack-blocks.svg?branch=master)](https://travis-ci.org/andywer/webpack-blocks)
44
[![Gitter chat](https://badges.gitter.im/webpack-blocks.svg)](https://gitter.im/webpack-blocks)
55

6-
Functional building blocks for your webpack config: easier way to configure webpack and to share configuration between projects.
6+
Functional building blocks for your webpack config: easier way to configure webpack and to share
7+
configuration between projects.
78

8-
Ready to use blocks to configure popular tools like *Babel*, *PostCSS*, *Sass*, *TypeScript*, etc., as well as best practices like extracting CSS — all with just one line of configuration.
9+
Ready to use blocks to configure popular tools like _Babel_, _PostCSS_, _Sass_, _TypeScript_, etc.,
10+
as well as best practices like extracting CSS — all with just one line of configuration.
911

10-
>"Finally, webpack config done right. (...) Webpack clearly wants to stay low-level. So it makes total sense to outsource configuring it to well designed blocks instead of copy-paste."
12+
> "Finally, webpack config done right. (...) Webpack clearly wants to stay low-level. So it makes
13+
> total sense to outsource configuring it to well designed blocks instead of copy-paste."
1114
>
12-
>[Dan Abramov](https://github.com/gaearon) via [twitter](https://twitter.com/dan_abramov/status/806249934399881216) (Co-author of Redux, Create React App and React Hot Loader)
13-
15+
> [Dan Abramov](https://github.com/gaearon) via
16+
> [twitter](https://twitter.com/dan_abramov/status/806249934399881216) (Co-author of Redux, Create
17+
> React App and React Hot Loader)
1418
1519
## Table of contents
1620

@@ -42,16 +46,16 @@ npm install --save-dev webpack webpack-blocks
4246
yarn add --dev webpack webpack-blocks
4347
```
4448

45-
4649
## Upgrade from v0.4
4750

4851
Check out our [migration guide](./docs/MIGRATION-GUIDE.md) to get started with v1.0 today.
4952

50-
5153
## Example
5254

53-
The following sample shows how to create a webpack config with Babel support, dev server and Autoprefixer.
55+
The following sample shows how to create a webpack config with Babel support, dev server and
56+
Autoprefixer.
5457

58+
<!-- prettier-ignore-start -->
5559
```js
5660
const webpack = require('webpack')
5761
const {
@@ -102,16 +106,17 @@ module.exports = createConfig([
102106
]),
103107
env('production', [
104108
uglify(),
105-
addPlugins([
106-
new webpack.LoaderOptionsPlugin({ minimize: true })
107-
])
109+
addPlugins([new webpack.LoaderOptionsPlugin({ minimize: true })])
108110
])
109111
])
110112
```
113+
<!-- prettier-ignore-end -->
111114

112115
See shorthand setters and helpers [documentation](packages/webpack#exports).
113116

114-
All blocks, like `babel` or `postcss` are also available as their own [small packages](./packages), `webpack-blocks` package wraps these blocks, shorthand setters and helpers as a single dependency for convenience.
117+
All blocks, like `babel` or `postcss` are also available as their own [small packages](./packages),
118+
`webpack-blocks` package wraps these blocks, shorthand setters and helpers as a single dependency
119+
for convenience.
115120

116121
## More examples
117122

@@ -151,30 +156,33 @@ Need a custom block? A simple block looks like this:
151156
```js
152157
module.exports = createConfig([
153158
// ...
154-
myCssLoader([ './styles' ])
159+
myCssLoader(['./styles'])
155160
])
156161

157-
function myCssLoader () {
158-
return (context, { merge }) => merge({
159-
module: {
160-
rules: [
161-
Object.assign(
162-
{
163-
test: /\.css$/,
164-
use: [ 'style-loader', 'my-css-loader' ]
165-
},
166-
context.match // carries `test`, `exclude` & `include` as set by `match()`
167-
)
168-
]
169-
}
170-
})
162+
function myCssLoader() {
163+
return (context, { merge }) =>
164+
merge({
165+
module: {
166+
rules: [
167+
Object.assign(
168+
{
169+
test: /\.css$/,
170+
use: ['style-loader', 'my-css-loader']
171+
},
172+
context.match // carries `test`, `exclude` & `include` as set by `match()`
173+
)
174+
]
175+
}
176+
})
171177
}
172178
```
173179
174-
If we use `myCssLoader` in `match()` then `context.match` will be populated with whatever we set in `match()`. Otherwise there is still the `test: /\.css$/` fallback, so our block will work without `match()` as well.
175-
176-
Check out the [sample app](./packages/sample-app) to see a webpack config in action or read [how to create your own blocks](./docs/BLOCK-CREATION.md).
180+
If we use `myCssLoader` in `match()` then `context.match` will be populated with whatever we set in
181+
`match()`. Otherwise there is still the `test: /\.css$/` fallback, so our block will work without
182+
`match()` as well.
177183
184+
Check out the [sample app](./packages/sample-app) to see a webpack config in action or read
185+
[how to create your own blocks](./docs/BLOCK-CREATION.md).
178186
179187
## Available webpack blocks
180188
@@ -192,7 +200,8 @@ Check out the [sample app](./packages/sample-app) to see a webpack config in act
192200
193201
## [Helpers](./packages/webpack#helpers)
194202
195-
Helpers allow you to structure your config and define settings for particular environments (like `production` or `development`) or file types.
203+
Helpers allow you to structure your config and define settings for particular environments (like
204+
`production` or `development`) or file types.
196205
197206
- group
198207
- env
@@ -201,7 +210,8 @@ Helpers allow you to structure your config and define settings for particular en
201210
202211
## [Shorthand setters](./packages/webpack#shorthand-setters)
203212
204-
Shorthand setters gives you easier access to common webpack settings, like plugins, entry points and source maps.
213+
Shorthand setters gives you easier access to common webpack settings, like plugins, entry points and
214+
source maps.
205215
206216
- addPlugins
207217
- customConfig
@@ -220,14 +230,16 @@ Shorthand setters gives you easier access to common webpack settings, like plugi
220230
- [webpack-blocks-happypack](https://github.com/diegohaz/webpack-blocks-happypack) — HappyPack
221231
- [webpack-blocks-less](https://github.com/kirill-konshin/webpack-blocks-less) — Less
222232
- [webpack-blocks-purescript](https://github.com/ecliptic/webpack-blocks-purescript) — PureScript
223-
- [webpack-blocks-server-source-map](https://github.com/diegohaz/webpack-blocks-server-source-map) — source map for server bundle
224-
- [webpack-blocks-split-vendor](https://github.com/diegohaz/webpack-blocks-split-vendor) — vendor bundle
225-
- [webpack-blocks-ts](https://github.com/foxbunny/webpack-blocks-ts) — TypeScript using ts-loader instead of awesome-typescript-loader
233+
- [webpack-blocks-server-source-map](https://github.com/diegohaz/webpack-blocks-server-source-map) —
234+
source map for server bundle
235+
- [webpack-blocks-split-vendor](https://github.com/diegohaz/webpack-blocks-split-vendor) — vendor
236+
bundle
237+
- [webpack-blocks-ts](https://github.com/foxbunny/webpack-blocks-ts) — TypeScript using ts-loader
238+
instead of awesome-typescript-loader
226239
- [webpack-blocks-vue](https://github.com/foxbunny/webpack-blocks-vue) — Vue
227240
228241
Missing something? Write and publish your own webpack blocks!
229242
230-
231243
## Design principles
232244
233245
- Extensibility first
@@ -240,7 +252,8 @@ Missing something? Write and publish your own webpack blocks!
240252
<details>
241253
<summary>How to debug?</summary>
242254
243-
In case the webpack configuration does not work as expected you can debug it using [q-i](https://www.npmjs.com/package/q-i):
255+
In case the webpack configuration does not work as expected you can debug it using
256+
[q-i](https://www.npmjs.com/package/q-i):
244257
245258
```js
246259
const { print } = require('q-i')
@@ -251,12 +264,14 @@ module.exports = createConfig([
251264

252265
print(module.exports)
253266
```
267+
254268
</details>
255269
256270
<details>
257271
<summary>How does env() work?</summary>
258272
259-
`env('development', [ ... ])` checks the `NODE_ENV` environment variable and only applies its contained webpack blocks if it matches the given string.
273+
`env('development', [ ... ])` checks the `NODE_ENV` environment variable and only applies its
274+
contained webpack blocks if it matches the given string.
260275
261276
So make sure you set the NODE_ENV accordingly:
262277
@@ -268,23 +283,37 @@ So make sure you set the NODE_ENV accordingly:
268283
}
269284
```
270285
271-
If there is no NODE_ENV set then it will treat NODE_ENV as if it was `development`. Use [cross-env](https://github.com/kentcdodds/cross-env) to make it work on all platforms.
286+
If there is no NODE_ENV set then it will treat NODE_ENV as if it was `development`. Use
287+
[cross-env](https://github.com/kentcdodds/cross-env) to make it work on all platforms.
288+
272289
</details>
273290
274291
<details>
275292
<summary>What does defineConstants() do?</summary>
276293
277-
`defineConstants()` is a small convenience wrapper around webpack's [DefinePlugin](https://webpack.github.io/docs/list-of-plugins.html#defineplugin). It is composable and automatically encodes the values. Use it to replace constants in your code by their values at build time.
294+
`defineConstants()` is a small convenience wrapper around webpack's
295+
[DefinePlugin](https://webpack.github.io/docs/list-of-plugins.html#defineplugin). It is composable
296+
and automatically encodes the values. Use it to replace constants in your code by their values at
297+
build time.
278298
279-
So having a `defineConstants({ 'process.env.FOO': 'foo' })` and a `defineConstants({ 'process.env.BAR': 'bar' })` in your config means the resulting webpack config will contain a single `new webpack.DefinePlugin({ 'process.env.FOO': '"FOO"', 'process.env.BAR': '"BAR"' })`, thus replacing any occurrence of `process.env.FOO` and `process.env.BAR` with the given values.
299+
So having a `defineConstants({ 'process.env.FOO': 'foo' })` and a
300+
`defineConstants({ 'process.env.BAR': 'bar' })` in your config means the resulting webpack config
301+
will contain a single
302+
`new webpack.DefinePlugin({ 'process.env.FOO': '"FOO"', 'process.env.BAR': '"BAR"' })`, thus
303+
replacing any occurrence of `process.env.FOO` and `process.env.BAR` with the given values.
304+
305+
You can also use [setEnv](./packages/webpack#setenvconstants-stringobject-function) method to define
306+
`process.env.*` variables, it’s based on
307+
[webpack.EnvironmentPlugin](https://webpack.js.org/plugins/environment-plugin/):
308+
`setEnv({ FOO: 'foo' })`.
280309
281-
You can also use [setEnv](./packages/webpack#setenvconstants-stringobject-function) method to define `process.env.*` variables, it’s based on [webpack.EnvironmentPlugin](https://webpack.js.org/plugins/environment-plugin/): `setEnv({ FOO: 'foo' })`.
282310
</details>
283311
284312
<details>
285313
<summary>What does a block look like from the inside?</summary>
286314
287-
A webpack block is *a function and requires no dependencies at all* (🎉🎉), thus making it easy to write your own blocks and share them with your team or the community.
315+
A webpack block is _a function and requires no dependencies at all_ (🎉🎉), thus making it easy to
316+
write your own blocks and share them with your team or the community.
288317
289318
Take the `babel` webpack block for instance:
290319
@@ -294,23 +323,26 @@ Take the `babel` webpack block for instance:
294323
* @param {RegExp|Function|string} [options.exclude] Directories to exclude.
295324
* @return {Function}
296325
*/
297-
function babel (options = { cacheDirectory: true }) {
298-
return (context, util) => util.addLoader(
299-
Object.assign({
300-
// we use a `MIME type => RegExp` abstraction here in order to have consistent regexs
301-
test: /\.(js|jsx)$/,
302-
exclude: /node_modules/,
303-
use: [
304-
{ loader: 'babel-loader', options }
305-
]
306-
}, context.match)
307-
)
326+
function babel(options = { cacheDirectory: true }) {
327+
return (context, util) =>
328+
util.addLoader(
329+
Object.assign(
330+
{
331+
// we use a `MIME type => RegExp` abstraction here in order to have consistent regexs
332+
test: /\.(js|jsx)$/,
333+
exclude: /node_modules/,
334+
use: [{ loader: 'babel-loader', options }]
335+
},
336+
context.match
337+
)
338+
)
308339
}
309340
```
310341
311342
Add a README and a package.json and you are ready to ship.
312343
313344
For more details see [How to write a block](./docs/BLOCK-CREATION.md).
345+
314346
</details>
315347
316348
<details>
@@ -337,51 +369,48 @@ module.exports = createConfig([
337369
customConfig({
338370
// Add some custom webpack config snippet
339371
resolve: {
340-
extensions: [ '.js', '.es6' ]
372+
extensions: ['.js', '.es6']
341373
}
342374
})
343375
])
344376
```
345377
346378
The object you pass to `customConfig()` will be merged into the webpack config using
347-
[webpack-merge](https://github.com/survivejs/webpack-merge) like any other webpack
348-
block's partial config.
379+
[webpack-merge](https://github.com/survivejs/webpack-merge) like any other webpack block's partial
380+
config.
381+
349382
</details>
350383
351384
<details>
352385
<summary>How to compose blocks?</summary>
353386
354-
Got some projects with similar, yet not identical webpack configurations? Create a “preset”, a function that returns a `group` of blocks so you can reuse it in multiple projects:
387+
Got some projects with similar, yet not identical webpack configurations? Create a “preset”, a
388+
function that returns a `group` of blocks so you can reuse it in multiple projects:
355389
356390
```js
357391
const { createConfig, env, group, babel, devServer } = require('webpack-blocks')
358392

359-
function myPreset (proxyConfig) {
360-
return group([
361-
babel(),
362-
env('development', [
363-
devServer(),
364-
devServer.proxy(proxyConfig)
365-
])
366-
])
393+
function myPreset(proxyConfig) {
394+
return group([babel(), env('development', [devServer(), devServer.proxy(proxyConfig)])])
367395
}
368396

369397
module.exports = createConfig([
370398
myPreset({
371399
'/api': { target: 'http://localhost:3000' }
372-
}),
400+
})
373401
// add more blocks here
374402
])
375403
```
376404
377-
The key feature is the `group()` method which takes a set of blocks and returns a new block that combines all their functionality.
378-
</details>
405+
The key feature is the `group()` method which takes a set of blocks and returns a new block that
406+
combines all their functionality.
379407
408+
</details>
380409
381410
## Like what you see?
382411
383-
Support webpack-blocks by giving [feedback](https://github.com/andywer/webpack-blocks/issues), publishing new webpack blocks or just by 🌟 starring the project!
384-
412+
Support webpack-blocks by giving [feedback](https://github.com/andywer/webpack-blocks/issues),
413+
publishing new webpack blocks or just by 🌟 starring the project!
385414
386415
## License
387416

0 commit comments

Comments
 (0)