Skip to content
This repository was archived by the owner on Mar 30, 2022. It is now read-only.

Commit ada4aea

Browse files
added setup file after env
1 parent 69cafd9 commit ada4aea

File tree

4 files changed

+53
-18
lines changed

4 files changed

+53
-18
lines changed

.eslintrc.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ module.exports = {
5555
}
5656
],
5757
"emotion/no-vanilla": "error",
58-
"emotion/styled-import": "error",
5958
"emotion/import-from-emotion": "error",
59+
"emotion/styled-import": "error",
6060
"react-hooks/rules-of-hooks": "error",
61-
'react-hooks/rules-of-hooks': 'error',
6261
'react-hooks/exhaustive-deps': 'off',
6362
'no-bitwise': 'off'
6463
},

jest.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
'.snap',
1818
],
1919
setupFiles: ['<rootDir>/jest.setup.js'],
20+
setupFilesAfterEnv: ['<rootDir>/jest.setupAfterEnv.js'],
2021
coverageReporters: ['json', 'lcov', 'text', 'text-summary'],
2122
moduleNameMapper: {
2223
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':

jest.setupAfterEnv.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { matchers } from 'jest-emotion';
2+
3+
expect.extend(matchers);

readme.md

+48-16
Original file line numberDiff line numberDiff line change
@@ -232,29 +232,61 @@ This is an example project setup with NextJs, Typescript, Eslint, Prettier, Jest
232232
},
233233
```
234234
235-
### [Styled-JSX](https://nextjs.org/blog/styling-next-with-styled-jsx)
236-
25. `npm i -P styled-jsx`
237-
26. `npm i -D @types/styled-jsx`
235+
### [EmotionJs](https://emotion.sh/docs/install)
236+
25. `npm i -P @emotion/core`
237+
26. `npm i -D @emotion/babel-preset-css-prop jest-emotion eslint-plugin-emotion`
238238
27. change `babel.config.js`
239239
```
240240
module.exports = {
241241
presets: [
242242
[
243243
'next/babel',
244244
{
245-
'styled-jsx': {},
246245
'preset-env': {},
247246
'preset-react': {},
248247
},
249248
],
249+
'@emotion/babel-preset-css-prop',
250250
],
251251
};
252252
```
253+
28. add rules and plugins to `.eslint.js`
254+
```
255+
module.exports = {
256+
// ...
257+
rules: {
258+
// ...
259+
"emotion/no-vanilla": "error",
260+
"emotion/import-from-emotion": "error",
261+
"emotion/styled-import": "error",
262+
},
263+
// ...
264+
plugins: [
265+
'emotion',
266+
// ...
267+
],
268+
// ...
269+
}
270+
```
271+
29. add `jest.setupAfterEnv.js`
272+
```
273+
import { matchers } from 'jest-emotion';
274+
275+
expect.extend(matchers);
276+
```
277+
30. add serializers and setup files to `jest.config.js`
278+
```
279+
// ...
280+
snapshotSerializers: ['enzyme-to-json/serializer', 'jest-emotion'],
281+
// ...
282+
setupFilesAfterEnv: ['<rootDir>/jest.setupAfterEnv.js'],
283+
// ...
284+
```
253285
254286
### [Deploy to Github Pages](https://github.com/zeit/next.js/issues/3335#issuecomment-489354854)
255287
(deploy to /docs intead of using gh-pages branch; replace `{folder}` with the project name in github repo)
256288
257-
28. create `linkPrefix` in `next.publicRuntimeConfig.js`
289+
31. create `linkPrefix` in `next.publicRuntimeConfig.js`
258290
```
259291
const isProd = process.env.NODE_ENV === 'production';
260292
const prodAssetPrefix = '/{folder}';
@@ -265,7 +297,7 @@ This is an example project setup with NextJs, Typescript, Eslint, Prettier, Jest
265297
prodAssetPrefix,
266298
};
267299
```
268-
29. create `assetPrefix` in `next.config.js`
300+
32. create `assetPrefix` in `next.config.js`
269301
```
270302
const publicRuntimeConfig = require('./ next.publicRuntimeConfig');
271303
const { linkPrefix, prodAssetPrefix } = publicRuntimeConfig;
@@ -275,7 +307,7 @@ This is an example project setup with NextJs, Typescript, Eslint, Prettier, Jest
275307
publicRuntimeConfig,
276308
};
277309
```
278-
30. change `as` prop in `next/Link` to add `linkPrefix`
310+
33. change `as` prop in `next/Link` to add `linkPrefix`
279311
```
280312
// ...
281313
import getConfig from 'next/config';
@@ -289,15 +321,15 @@ This is an example project setup with NextJs, Typescript, Eslint, Prettier, Jest
289321
);
290322
// ...
291323
```
292-
31. change `scripts` in `package.json`
324+
34. change `scripts` in `package.json`
293325
```
294326
"export": "npm run build && next export",
295327
"deploy": "NODE_ENV=production npm run build && next export -o docs && touch docs/.nojekyll",
296328
```
297329
298330
### [ServiceWorker](https://gist.github.com/kosamari/7c5d1e8449b2fbc97d372675f16b566e)
299-
32. `npm i -P next-offline`
300-
33. add to `next.config.js` to make `service-worker.js` available at the root of project folder
331+
35. `npm i -P next-offline`
332+
36. add to `next.config.js` to make `service-worker.js` available at the root of project folder
301333
```
302334
const withOffline = require('next-offline');
303335
//...
@@ -322,7 +354,7 @@ This is an example project setup with NextJs, Typescript, Eslint, Prettier, Jest
322354
//...
323355
});
324356
```
325-
34. add `<link rel="canonical" href="/{folder}" />` to `<Head />` to force redirected to `/{folder}` and allow scope of service worker works under `/{folder}/` (without [adding `service-worker-allowed` header in repsonse header](https://medium.com/dev-channel/two-http-headers-related-to-service-workers-you-never-may-have-heard-of-c8862f76cc60) to request for greater scope)
357+
37. add `<link rel="canonical" href="/{folder}" />` to `<Head />` to force redirected to `/{folder}` and allow scope of service worker works under `/{folder}/` (without [adding `service-worker-allowed` header in repsonse header](https://medium.com/dev-channel/two-http-headers-related-to-service-workers-you-never-may-have-heard-of-c8862f76cc60) to request for greater scope)
326358
```
327359
<Head>
328360
<Link href="/" passHref>
@@ -332,8 +364,8 @@ This is an example project setup with NextJs, Typescript, Eslint, Prettier, Jest
332364
```
333365
334366
### [Web Mainfest](https://www.npmjs.com/package/next-manifest)
335-
35. `npm i -P next-manifest`
336-
36. add to `next.config.js` to make `manifest.json` available at `/static/manifest/manifest.json`
367+
38. `npm i -P next-manifest`
368+
39. add to `next.config.js` to make `manifest.json` available at `/static/manifest/manifest.json`
337369
```
338370
//...
339371
const withManifest = require('next-manifest');
@@ -372,7 +404,7 @@ This is an example project setup with NextJs, Typescript, Eslint, Prettier, Jest
372404
})
373405
);
374406
```
375-
37. Create `<ManifestHead>` to hold mainfest related head elements and add support to other browsers
407+
40. Create `<ManifestHead>` to hold mainfest related head elements and add support to other browsers
376408
```
377409
//...
378410
import NextHead from 'next/head';
@@ -442,7 +474,7 @@ This is an example project setup with NextJs, Typescript, Eslint, Prettier, Jest
442474
);
443475
//...
444476
```
445-
38. import the `<ManifestHead>` in the page
477+
41. import the `<ManifestHead>` in the page
446478
```
447479
//...
448480
import ManifestHead from '../src/components/Head/ManifestHead';
@@ -459,7 +491,7 @@ This is an example project setup with NextJs, Typescript, Eslint, Prettier, Jest
459491
/>
460492
//..
461493
```
462-
39. Make icons files (favicon.ico, icon*.png) available in the static folder
494+
42. Make icons files (favicon.ico, icon*.png) available in the static folder
463495
464496
## Usage of this example setup
465497
1. remove unwanted files in `static/`, `src/utils`, `src/__tests/`, `src/components`, and `pages`

0 commit comments

Comments
 (0)