Skip to content

Commit 36e7dea

Browse files
committed
Add instruction for usage with package.json
1 parent 8e8baec commit 36e7dea

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,51 @@ This command will run a `webpack-dev-server` and serve your bundle.
3939

4040
Navigate to the [example directory](https://github.com/mesaugat/swift-react/tree/master/example) to see `swift-react` in action.
4141

42+
## Usage with package.json
43+
44+
Add `swift-react` as a dev dependency.
45+
46+
```bash
47+
$ yarn add swift-react --dev
48+
```
49+
50+
```json
51+
// package.json
52+
53+
{
54+
"name": "swift-react-example",
55+
"scripts": {
56+
"swift-react": "swift-react"
57+
},
58+
"devDependencies": {
59+
"swift-react": "*"
60+
}
61+
}
62+
```
63+
64+
Next, create an `index.js` file right next to your `package.json` file.
65+
66+
```js
67+
// index.js
68+
69+
function App() {
70+
return (
71+
<h1>Hello swift-react</h1>
72+
);
73+
}
74+
75+
// Caution: You don't need to import React or ReactDOM for swift-react to work.
76+
ReactDOM.render(<App />, document.getElementById('root'));
77+
```
78+
79+
Finally, run this command from the exact place where you created the `package.json` and `index.js` file.
80+
81+
```bash
82+
$ yarn swift-react
83+
```
84+
85+
*The advantage of this method as compared to the first one is that you don't have to download dependencies of `swift-react` again and again.*
86+
4287
## Motivation
4388

4489
Sometimes testing a small React quirkiness is too cumbersome.

0 commit comments

Comments
 (0)