1 | # Gnoll :japanese_ogre:
|
2 |
|
3 | Tool for fast and easy bootstraping Webpack & React projects.
|
4 | It can perform basic tasks without any configuration files.
|
5 | But if you need to change some settings, you can create config files
|
6 | in 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 | ```
|
18 | npm install gnoll
|
19 | ```
|
20 |
|
21 | Gnoll has command line interface.
|
22 | You 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 |
|
37 | Creates 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 –
|
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 |
|
104 | Creates development build and rebuild on changes.
|
105 | <br>
|
106 | This command has same options as `build`, but
|
107 | default value for the `--env` option is `development`
|
108 |
|
109 | ### gnoll start
|
110 |
|
111 | Starts webpack development server.
|
112 | <br>
|
113 | Options are the same as for `build` command except for
|
114 | `--env` (it always is set to `development`) and `--target` (always is `web`)
|
115 | <br>
|
116 | This command uses [webpack-serve](https://github.com/webpack-contrib/webpack-serve) module.
|
117 | You can configure it in the section `serve` in the `webpack.config.js` file.
|
118 |
|
119 | ### gnoll lib
|
120 |
|
121 | Use this command if you want to build library that should provide modules.
|
122 | <br>
|
123 | When building library, js files are compiled by Babel.
|
124 | Format of the modules is changed to CommonJS.
|
125 | All 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>
|
133 | Default: `./src`
|
134 |
|
135 | `-o, --out`
|
136 | <br>
|
137 | Default: `./lib`
|
138 |
|
139 | `--watch`
|
140 | <br>
|
141 | Starts watcher that recompiles files on changes.
|
142 |
|
143 | `--source-maps`
|
144 | <br>
|
145 | Embed inline source maps into compiled files.
|
146 |
|
147 | ## Configuration
|
148 |
|
149 | This section describes how you can change configuration.
|
150 |
|
151 | ### Webpack
|
152 |
|
153 | Default 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 |
|
161 | Building 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 |
|
164 | If you want to change something in the webpack config, you can create
|
165 | `webpack.config.js` in your project and extend the default config.
|
166 | For convenience, you can use
|
167 | [webpack-merge](https://github.com/survivejs/webpack-merge)
|
168 | for merging several webpack configs.
|
169 |
|
170 | ```js
|
171 | const merge = require('webpack-merge')
|
172 | const baseConfig = require('gnoll/config/webpack')
|
173 |
|
174 | module.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 |
|
192 | Javascript is compiled with Babel.
|
193 | Default config uses following presets:
|
194 | - `@babel/preset-env` (ES6 syntax features)
|
195 | - `@babel/preset-react` (JSX syntax)
|
196 |
|
197 | If 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
|
199 | in the `package.json`.
|
200 |
|
201 | For example, this is how you can add support for decorators:
|
202 | ```js
|
203 | // babel.config.js
|
204 | const baseConfig = require('gnoll/config/babel')
|
205 |
|
206 | module.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 | ```
|
222 | NODE_ENV
|
223 | GNOLL_TARGET
|
224 | GNOLL_ASSETS_CACHING
|
225 | GNOLL_DEV_SERVER
|
226 | GNOLL_SERVER_RENDERING
|
227 | GNOLL_LIB
|
228 | ```
|
229 |
|
230 | ## License
|
231 |
|
232 | Public domain, see the LICENCE file.
|