UNPKG

5.41 kBMarkdownView Raw
1# Gnoll :japanese_ogre:
2
3Tool for fast and easy bootstraping Webpack & React projects.
4It can perform basic tasks without any configuration files.
5But if you need to change some settings, you can create config files
6in the your project and extend the default configuration.
7
8## Table of content
9
10- [Install](#install)
11- [Commands](#commands)
12- [Configuration](#configuration)
13- [License](#license)
14
15## Install
16
17```
18npm install gnoll
19```
20
21Gnoll has command line interface.
22You can add commands to the `package.json` file:
23
24```json
25{
26 "scripts": {
27 "start": "gnoll start",
28 "build": "gnoll build"
29 }
30}
31```
32
33## Commands
34
35### gnoll build
36
37Creates optimized production build.
38
39#### Options
40
41- `-e, --entry path`
42 <br>
43 Default: `./src/index.js`
44 <br>
45 Webpack entry file.
46
47- `-o, --out path`
48 <br>
49 Default: `./build`
50 <br>
51 Path to the output directory.
52
53- `--html path/to/index.html`
54 <br>
55 Default: `./src/index.html` (if exists)
56 <br>
57 Page that will be bundled with automatically injected assets
58 using `html-webpack-plugin`.
59 <br>
60 If you want to explicitly disable building html, use option `--no-html`.
61
62- `--config path/to/webpack.config.js`
63 <br>
64 This option allows to provide path to the custom webpack config file.
65
66- `--env=development|production`
67 <br>
68 Default: `production`
69 <br>
70 Value of the `NODE_ENV` environment variable.
71
72- `--target=web|node`
73 <br>
74 Default: `web`
75 <br>
76 This options allows to specify target platform.
77 - Sets webpack `target` option
78 - When target is `node` sets `ligraryTarget` to `commonjs`
79 - Sets `targets` options of the `@babel/preset-env`
80 (unless you override it using any method supported by
81 [browserslist](https://github.com/browserslist/browserslist#queries))
82
83- `-o, --optimize-caching`
84 <br>
85 This option enables optimizations for long term caching of static assets.
86 <br>
87 Optimizations are based on this guide from webpack documentation &ndash;
88 https://webpack.js.org/guides/caching/
89 - It inserts hash of file content in its filename.
90 This allows to cache files forever, because changed files will always have
91 different names.
92 - Generates `manifest.json` file that maps original filenames to hashed
93 ones.
94
95- `--ssr`
96 <br>
97 Creates bundle for server side rendering.
98 - Sets target to `node`.
99 - Disables output of the static files and styles.
100 - Disables bundling html page.
101
102### gnoll watch
103
104Creates development build and rebuild on changes.
105<br>
106This command has same options as `build`, but
107default value for the `--env` option is `development`
108
109### gnoll start
110
111Starts webpack development server.
112<br>
113Options are the same as for `build` command except for
114`--env` (it always is set to `development`) and `--target` (always is `web`)
115<br>
116This command uses [webpack-serve](https://github.com/webpack-contrib/webpack-serve) module.
117You can configure it in the section `serve` in the `webpack.config.js` file.
118
119### gnoll lib
120
121Use this command if you want to build library that should provide modules.
122<br>
123When building library, js files are compiled by Babel.
124Format of the modules is changed to CommonJS.
125All other files are copied as is. Result is placed in the `lib` directory.
126
127**Options:**
128
129`--target=web|node`
130
131`-e, --entry`
132<br>
133Default: `./src`
134
135`-o, --out`
136<br>
137Default: `./lib`
138
139`--watch`
140<br>
141Starts watcher that recompiles files on changes.
142
143`--source-maps`
144<br>
145Embed inline source maps into compiled files.
146
147## Configuration
148
149This section describes how you can change configuration.
150
151### Webpack
152
153Default webpack config includes following loaders:
154
155- `babel-loader` for `js` and `jsx` files
156- `file-loader` for the following formats:
157 - images: `png` `svg` `jpg` `jpeg` `gif` `webp`
158 - fonts: `eot` `ttf` `woff` `woff2`
159 - media: `mp4` `ogg` `webm` `mp3`
160
161Building styles is not included in gnoll by default, but you can add it with
162[gnoll-styles](https://github.com/sunflowerdeath/gnoll/tree/master/packages/gnoll-styles) plugin.
163
164If you want to change something in the webpack config, you can create
165`webpack.config.js` in your project and extend the default config.
166For convenience, you can use
167[webpack-merge](https://github.com/survivejs/webpack-merge)
168for merging several webpack configs.
169
170```js
171const merge = require('webpack-merge')
172const baseConfig = require('gnoll/config/webpack')
173
174module.exports = merge(baseConfig, {
175 plugins [
176 somePlugin
177 ],
178 module: {
179 rules: [
180 { test: /\.smth$/, loader: 'some-loader' }
181 ]
182 }
183}
184```
185
186#### Extracting vendor and runtime chunks
187
188_TODO_
189
190### Babel
191
192Javascript is compiled with Babel.
193Default config uses following presets:
194- `@babel/preset-env` (ES6 syntax features)
195- `@babel/preset-react` (JSX syntax)
196
197If you want to change change babel config, you can create `.babelrc` or
198`babel.config.js` file in the your project or set `babel` property
199in the `package.json`.
200
201For example, this is how you can add support for decorators:
202```js
203// babel.config.js
204const baseConfig = require('gnoll/config/babel')
205
206module.exports = {
207 ...baseConfig,
208 plugins: [
209 ['@babel/plugin-proposal-decorators', { legacy: true }],
210 ['@babel/plugin-proposal-class-properties', { loose: true }]
211 ]
212}
213```
214
215### Browsers
216
217_TODO_
218
219### Env vars
220
221```
222NODE_ENV
223GNOLL_TARGET
224GNOLL_ASSETS_CACHING
225GNOLL_DEV_SERVER
226GNOLL_SERVER_RENDERING
227GNOLL_LIB
228```
229
230## License
231
232Public domain, see the LICENCE file.