1 | # @anansi/webpack-config
|
2 | A webpack configuration for fast development and production ready optimizations
|
3 |
|
4 | ## Usage
|
5 |
|
6 | /webpack.config.babel.js
|
7 |
|
8 | ```javascript
|
9 | import { makeConfig } from '@anansi/webpack-config'
|
10 |
|
11 | export const options = {
|
12 | basePath: 'src',
|
13 | buildDir: 'generated_assets/',
|
14 | }
|
15 |
|
16 | export 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 |
|
34 | Set `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 |
|
47 | Pass these to makeConfig.
|
48 |
|
49 | ### libraryInclude/libraryExclude
|
50 |
|
51 | Regex to match libraries to include in the normal build process. This is useful for
|
52 | locally developed modules or `yarn workspaces`. Not this should point to the installed
|
53 | location, rather than the actual target. Note you'll need both the positive and negative
|
54 | regexes.
|
55 |
|
56 | To match all libraries in namespace `@myspacespace`:
|
57 | ```
|
58 | const myConfig = makeConfig({
|
59 | libraryInclude: /node_modules\/(@mynamespace\/)/,
|
60 | libraryExclude: /node_modules(?!\/(@mynamespace\/))/,
|
61 | })
|
62 | ```
|
63 |
|
64 | ### basePath = 'src'
|
65 |
|
66 | Marks the base directory inside the package for javascript source files. This
|
67 | is used to make it easy to import from the root.
|
68 |
|
69 | Example:
|
70 | ```
|
71 | -package.json
|
72 | -/src
|
73 | -/components
|
74 | -/pages
|
75 | -/utils
|
76 | -network.js
|
77 | ```
|
78 | Then you can do
|
79 | ```javascript
|
80 | import fetch from 'network'
|
81 | ```
|
82 | from any file.
|
83 |
|
84 | ### buildDir = 'generated_assets/'
|
85 |
|
86 | Output 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
|