UNPKG

4.57 kBMarkdownView Raw
1# Gnoll :japanese_ogre:
2
3Tool for fast and easy bootstraping Webpack & React projects.
4
5- It can build code in production and development modes,
6and perform other tasks like linting and formatting.
7- It includes all required dependencies, so you don't need to install them manually.
8- It contains default configuration, but if you need to change some settings,
9you can override them in your project.
10
11## Install
12
13```
14npm install gnoll
15```
16
17## Commands
18
19Gnoll has command line interface. You can add commands to your `package.json` file:
20
21```json
22{
23 "scripts": {
24 "start": "gnoll start",
25 "build": "gnoll build",
26 "lint": "gnoll lint"
27 }
28}
29```
30
31### build [--config path] \[--caching]
32
33Creates optimized production build.
34
35It builds entry `src/index.js` and outputs results to `dist` dir.
36You can read in next section what is included in default config.
37<br>
38If you want to change something, for example, add plugins or loaders,
39you can extend default config by creating `webpack.config.js` in your project.
40
41```js
42// webpack.config.js
43
44// default config
45let config = require('gnoll/config/webpack')
46
47// add plugin
48config.plugins.push(plugin)
49
50// add loader
51config.module.rules.push({
52 test: /\.smth$/,
53 loader: 'some-loader'
54})
55
56module.exports = config
57```
58
59**`--config path`**
60<br>
61This option allows to provide path to different webpack config file.
62
63**`--caching`**
64<br>
65This option optimizes build for long term caching of static assets.
66<br>
67Optimizations are based on this guide from webpack documentation -
68https://webpack.js.org/guides/caching/
69
70- It includes hash of file content in its filename.
71This allows to cache files forever, because changed files will always have different names.
72- Extracts webpack runtime into separate entry chunk `runtime`, because it can change on rebuild.
73- Generates `manifest.json` file that maps original filenames to hashed ones.
74
75Also, it is common practice to separate some vendor modules to separate bundle.
76You can do it by extending webpack config file in your project like this:
77
78```js
79config.entry = {
80 main: './src/index.js',
81 vendor: ['react', 'react-dom']
82}
83
84// Note that the plugin is added to the beginning.
85// It is important to insert it before CommonsChunkPlugin that extracts 'runtime'
86config.plugins.unshift(new webpack.optimize.CommonsChunkPlugin({
87 name: 'vendor',
88 minChunks: Infinity
89}))
90```
91
92### watch [--config path]
93
94Creates development build and rebuild on changes.
95
96### start [--config path]
97
98Starts webpack development server.
99
100If you have file `src/index.html` in your project, it will be included
101using `html-webpack-plugin` and served on dev-server with automatically injected assets.
102
103### lib [--watch] [--source-maps]
104
105Use this command if you want to build library that should provide modules.
106<br>
107When building library, js files are compiled by Babel.
108Format of the modules is changed to CommonJS.
109All other files are copied as is. Result is placed in the `lib` directory.
110
111**`--watch`**
112<br>
113Starts watcher that recompiles files on changes.
114
115**`--source-maps`**
116<br>
117Embed inline source maps into compiled files.
118
119### lint
120
121Checks source code with [ESLint](https://eslint.org).
122
123Default config is based on `eslint-config-airbnb` with addition of `eslint-config-prettier`,
124which removes all rules related to formatting and replaces them with rule
125that gives error when source code doesn't match autoformatted output from the Prettier.
126
127If you need to integrate linting with your IDE or editor plugin, you should
128create `.eslintrc.js` file in your project and extend the default config like this:
129
130```js
131// .eslintrc.js
132module.exports = {
133 extends: [
134 './node_modules/gnoll/config/eslint.js'
135 ]
136}
137```
138
139Also, you can override any ESLint settings in this file, if you want.
140
141If you want to change Prettier settings, you can create `.prettierrc` (JSON format)
142or `prettier.config.js` (JS module) in your project.
143
144## Included loaders
145
146### Javascript
147
148Javascript is compiled using Babel.
149<br>
150In addition to ES6 syntax features, it also supports:
151
152- Unfinished proposals to the ES standard
153 ([`babel-preset-stage-0`](https://babeljs.io/docs/plugins/preset-stage-0/))
154- JSX syntax
155- Decorators ([`babel-plugin-transform-decorators-legacy`](
156 https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy))
157
158When building for production code is minified by UglifyJS.
159
160### Static files
161
162These formats are built using `file-loader`:
163
164- images: `png` `svg` `jpg` `jpeg` `gif` `webp`
165- fonts: `eot` `ttf` `woff` `woff2`
166- media: `mp4` `ogg` `webm` `mp3`