UNPKG

2.23 kBMarkdownView Raw
1# @anansi/webpack-config
2A webpack configuration for fast development and production ready optimizations
3
4## Usage
5
6/webpack.config.babel.js
7
8```javascript
9import { makeConfig } from '@anansi/webpack-config'
10
11export const options = {
12 basePath: 'src',
13 buildDir: 'generated_assets/',
14}
15
16export default makeConfig(options)
17```
18
19/package.json
20```json
21{
22 "scripts": {
23 "start:dev": "webpack-dev-server --config=webpack.config.babel.js --mode=development",
24 "build": "webpack --config=webpack.config.babel.js --mode=production",
25 "analyze": "WEBPACK_ANALYZE=true webpack --config=webpack.config.babel.js --mode=production"
26 }
27}
28```
29
30## Env customization
31
32### WEBPACK_ANALYZE
33
34Set `WEBPACK_ANALYZE` to "true" to build a static [treemap visualization of your packages](https://www.npmjs.com/package/webpack-bundle-analyzer).
35
36/package.json
37```json
38{
39 "scripts": {
40 "analyze": "WEBPACK_ANALYZE=true webpack --config=webpack.config.babel.js --mode=production"
41 }
42}
43```
44
45## Options
46
47Pass these to makeConfig.
48
49### libraryInclude/libraryExclude
50
51Regex to match libraries to include in the normal build process. This is useful for
52locally developed modules or `yarn workspaces`. Not this should point to the installed
53location, rather than the actual target. Note you'll need both the positive and negative
54regexes.
55
56To match all libraries in namespace `@myspacespace`:
57```
58const myConfig = makeConfig({
59 libraryInclude: /node_modules\/(@mynamespace\/)/,
60 libraryExclude: /node_modules(?!\/(@mynamespace\/))/,
61})
62```
63
64### basePath = 'src'
65
66Marks the base directory inside the package for javascript source files. This
67is used to make it easy to import from the root.
68
69Example:
70```
71-package.json
72-/src
73 -/components
74 -/pages
75 -/utils
76 -network.js
77```
78Then you can do
79```javascript
80import fetch from 'network'
81```
82from any file.
83
84### buildDir = 'generated_assets/'
85
86Output directory for production build files
87
88## File Support
89
90* SCSS with CSS modules
91 * Use `${basePath}/style/export.scss` to add variables or mixins avaiable in all scss files
92 * Put global styles within `${basePath}/style`
93 * Other styles will be treated as css modules
94* Web workers
95* All font formats
96* Any media files
97* And of course javascript