You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
7
8
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.
9
11
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."
11
14
>
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
See shorthand setters and helpers [documentation](packages/webpack#exports).
113
116
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.
115
120
116
121
## More examples
117
122
@@ -151,30 +156,33 @@ Need a custom block? A simple block looks like this:
151
156
```js
152
157
module.exports=createConfig([
153
158
// ...
154
-
myCssLoader(['./styles'])
159
+
myCssLoader(['./styles'])
155
160
])
156
161
157
-
functionmyCssLoader () {
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
+
functionmyCssLoader() {
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
+
})
171
177
}
172
178
```
173
179
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.
177
183
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).
178
186
179
187
## Available webpack blocks
180
188
@@ -192,7 +200,8 @@ Check out the [sample app](./packages/sample-app) to see a webpack config in act
192
200
193
201
## [Helpers](./packages/webpack#helpers)
194
202
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.
196
205
197
206
- group
198
207
- env
@@ -201,7 +210,8 @@ Helpers allow you to structure your config and define settings for particular en
`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.
260
275
261
276
So make sure you set the NODE_ENV accordingly:
262
277
@@ -268,23 +283,37 @@ So make sure you set the NODE_ENV accordingly:
268
283
}
269
284
```
270
285
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
+
272
289
</details>
273
290
274
291
<details>
275
292
<summary>What does defineConstants() do?</summary>
276
293
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.
278
298
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 `newwebpack.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
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' })`.
282
310
</details>
283
311
284
312
<details>
285
313
<summary>What does a block look like from the inside?</summary>
286
314
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.
288
317
289
318
Take the `babel` webpack block for instance:
290
319
@@ -294,23 +323,26 @@ Take the `babel` webpack block for instance:
294
323
* @param{RegExp|Function|string}[options.exclude] Directories to exclude.
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
+
349
382
</details>
350
383
351
384
<details>
352
385
<summary>How to compose blocks?</summary>
353
386
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:
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.
379
407
408
+
</details>
380
409
381
410
## Like what you see?
382
411
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!
0 commit comments