File size: 3,772 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Gotchas

These are some things to be aware of when using this boilerplate.

- [Special images in HTML files](#special-images-in-html-files)
- [Load reducers optimistically](#load-reducers-optimistically)
- [Exclude modules from Babel processing](#exclude-modules-from-babel-processing)
- [Running tests in `watch` mode](#running-tests-in-watch-mode)
- [When in doubt, re-install!](#when-in-doubt-re-install)
- [Cleaning up Jest cache](#cleaning-up-jest-cache)
- [Using short_name in Web App manifest](#using-short_name-in-web-app-manifest)

## Special images in HTML files

If you specify your images in the `.html` files using the `<img>` tag, everything
will work fine. The problem comes up if you try to include images using anything
except that tag, like meta tags:

```HTML
<meta property="og:image" content="img/yourimg.png" />
```

The webpack `html-loader` does not recognise this as an image file and will not
transfer the image to the build folder. To get webpack to transfer them, you
have to import them with the file loader in your JavaScript somewhere, e.g.:

```JavaScript
import 'file?name=[name].[ext]!../img/yourimg.png';
```

Then webpack will correctly transfer the image to the build folder.

## Load reducers optimistically

If you have containers that should be available throughout the app, like a `NavigationBar` (they aren't route specific), you need to add their respective reducers to the root reducer with the help of `combineReducers`.

```js
// In app/reducers.js

...
import { combineReducers } from 'redux';
...

import navigationBarReducer from 'containers/NavigationBar/reducer';

export default function createReducer(injectedReducers = {}) {
  const rootReducer = combineReducers({
    global: globalReducer,
    language: languageProviderReducer,
    router: connectRouter(history),
    navigationBar: navigationBarReducer,
    ...injectedReducers,
  });

  return rootReducer;
}
```

## Exclude modules from Babel processing

You need to exclude packages which are not intended to be processed by babel. For e.g. Server packages such as 'express' or a CSS file. Just add the package name to `exclude` array in `internals/config.js` and you're all set!

```js
// in internals/config.js

exclude: [
  'chalk',
  'compression',
  'cross-env',
  'express',
  'ip',
  'minimist',
  'sanitize.css',
  'your-unwanted-package', <- add your-unwanted-package
  ...
]
```

## Running tests in `watch` mode

If you are unable to run tests in watch mode, you may have to install `watchman` for this to work. If you're using a Mac, simply run `brew install watchman`

You can also install `watchman` from source. Please visit their [official guide](https://facebook.github.io/watchman/docs/install.html) for more information.

## When in doubt, re-install!

If you're facing any inexplicable problems while installing dependencies, building your project or running tests, try reinstalling dependencies. It works for most cases. Run the following commands in the exact order given:

Remove node_modules

- `rm -rf node_modules`

Clear cache

- `npm cache clean`

Re-install dependencies

- `npm install`

Build project

- `npm run build`

## Cleaning up Jest cache

By default, Jest caches transformed modules, which may lead to faulty coverage reports. To prevent this, you'll have to clear the cache by running `npm run test -- --no-cache` as pointed out in [Jest docs](https://facebook.github.io/jest/docs/cli.html#cache)

## Using short_name in Web App manifest

When there's insufficient space to display an app's full name it is truncated.
This happens with app launcher and new tab in Chrome for Android.
The `short_name` field allows a _12 character or less abbreviation_.
It also addresses any problems in testing the PWA in Lighthouse.