README.md 1.3 KB
Newer Older
1
[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/shared-modules)
2 3
# Example app using shared modules

D
Dan Zajdband 已提交
4
## How to use
5

6 7
### Using `create-next-app`

8
Execute [`create-next-app`](https://github.com/segmentio/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example:
9

10 11 12 13
```bash
npx create-next-app --example shared-modules shared-modules-app
# or
yarn create next-app --example shared-modules shared-modules-app
14 15 16 17
```

### Download manually

S
Sébastien Dubois 已提交
18
Download the example [or clone the repo](https://github.com/zeit/next.js):
D
Dan Zajdband 已提交
19 20

```bash
21
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/shared-modules
N
nkzawa 已提交
22
cd shared-modules
D
Dan Zajdband 已提交
23
```
24

D
Dan Zajdband 已提交
25
Install it and run:
D
Dan Zajdband 已提交
26 27

```bash
28
npm install
D
Dan Zajdband 已提交
29
npm run dev
30 31 32
# or
yarn
yarn dev
D
Dan Zajdband 已提交
33 34
```

D
Dan Zajdband 已提交
35
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
D
Dan Zajdband 已提交
36 37

```bash
D
Dan Zajdband 已提交
38
now
39
```
D
Dan Zajdband 已提交
40 41 42 43 44 45 46

## The idea behind the example

This example features:

* An app with two pages which has a common Counter component
* That Counter component maintain the counter inside its module. This is used primarily to illustrate that modules get initialized once and their state variables persist in runtime