UNPKG

4.98 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|universal`
73 <br>
74 Default: `web`
75 <br>
76 This options allows to specify target platform.
77 - sets webpack `target` option
78 - sets env of the `@babel/preset-env`
79 - when target is `node` or `universal` sets `ligraryTarget` to `commonjs`
80
81- `-o, --optimize-caching`
82 <br>
83 This option enables optimizations for long term caching of static assets.
84 <br>
85 Optimizations are based on this guide from webpack documentation &ndash;
86 https://webpack.js.org/guides/caching/
87 - It inserts hash of file content in its filename.
88 This allows to cache files forever, because changed files will always have
89 different names.
90 - Generates `manifest.json` file that maps original filenames to hashed
91 ones.
92
93### gnoll watch
94
95Creates development build and rebuild on changes.
96<br>
97This command has same options as `build`, but
98default value for the `--env` option is `development`
99
100### gnoll start
101
102Starts webpack development server.
103<br>
104This command has the same options as `build` except for
105`--env` (it always is set to `development`) and `--target` (always is `web`)
106
107### gnoll lib
108
109Use this command if you want to build library that should provide modules.
110<br>
111When building library, js files are compiled by Babel.
112Format of the modules is changed to CommonJS.
113All other files are copied as is. Result is placed in the `lib` directory.
114
115**Options:**
116
117`--target=web|node`
118
119`-e, --entry`
120<br>
121Default: `./src`
122
123`-o, --out`
124<br>
125Default: `./lib`
126
127`--watch`
128<br>
129Starts watcher that recompiles files on changes.
130
131`--source-maps`
132<br>
133Embed inline source maps into compiled files.
134
135## Configuration
136
137This section describes how you can change configuration.
138
139### Webpack
140
141Default webpack config includes following loaders:
142
143- `babel-loader` for `js` and `jsx` files
144- `file-loader` for the following formats:
145 - images: `png` `svg` `jpg` `jpeg` `gif` `webp`
146 - fonts: `eot` `ttf` `woff` `woff2`
147 - media: `mp4` `ogg` `webm` `mp3`
148
149Building styles is not included in gnoll by default, but you can add it with
150[gnoll-scss](https://github.com/sunflowerdeath/gnoll/tree/master/packages/gnoll-scss) plugin.
151
152If you want to change something in the webpack config, you can create
153`webpack.config.js` in your project and extend the default config.
154For convenience, you can use
155[webpack-merge](https://github.com/survivejs/webpack-merge)
156for merging several webpack configs.
157
158```js
159const merge = require('webpack-merge')
160const baseConfig = require('gnoll/config/webpack')
161
162module.exports = merge(baseConfig, {
163 plugins [
164 somePlugin
165 ],
166 module: {
167 rules: [
168 { test: /\.smth$/, loader: 'some-loader' }
169 ]
170 }
171}
172```
173
174#### Extracting vendor and runtime chunks
175
176_TODO_
177
178### Babel
179
180Javascript is compiled with Babel.
181Default config uses following presets:
182- `babel-preset-env` (ES6 syntax features)
183- `babel-preset-react` (JSX syntax)
184- `babel-preset-stage-0` (Unfinished proposals to the ES standard)
185
186If you want to change change babel config, you can create `.babelrc` or
187`babel.config.js` file in the your project or set `babel` property
188in the `package.json`.
189
190For example, this is how you can add support for decorators:
191```js
192// babel.config.js
193const baseConfig = require('gnoll/config/babel')
194
195module.exports = {
196 ...baseConfig,
197 plugins: [
198 ['@babel/plugin-proposal-class-properties', { loose: true }],
199 '@babel/plugin-proposal-decorators',
200 ]
201}
202```
203
204### Browsers
205
206_TODO_
207
208### Env vars
209
210```
211NODE_ENV
212GNOLL_TARGET
213GNOLL_ASSETS_CACHING
214GNOLL_DEV_SERVER
215GNOLL_LIB
216```
217
218## License
219
220Public domain, see the LICENCE file.