48
loading...
This website collects cookies to deliver better user experience
Please download full source code from KPITENG GitHub.
> wml add common /app/node_modules/@sharecode/common
"workspaces": {
"nohoist": [
"react-native",
"react-native/**",
"react",
"react/**"
]
}
> mkdir react-share-code
> cd mkdir
{
"private": true,
"name": "react-share-code",
"version": "1.0.0",
"workspaces": [
"app", "web", "common"
]
}
> npx react-native init app // this will create react native application
> npx create-react-app web // this will create react.js application
> mkdir common // this is our common directory for code share
> cd common
> yarn init -y // this will create package.json file with following code
/common/package.json
{
"name": "common",
"version": "1.0.0",
"description": "...",
…
}
> ls // it will print following
app web common package.json
> mkdir packages
> mv app/ packages/app/
> mv web/ packages/app/
> mv common/ packages/app/
{
"private": true,
"name": "react-share-code",
"version": "1.0.0",
"workspaces": [
"packages/*"
]
}
{
- "name": "app",
+ "name": "@sharecode/app"
}
{
- "name": "web",
+ "name": "@sharecode/web"
}
{
- "name": "common",
+ "name": "@sharecode/common"
}
export const sharedVariable = “Shared Variable”;
{
"devDependencies": {
+ "@sharecode/common": "1.0.0"
},
+ "workspaces": {
+ "nohoist": [
+ "react-native",
+ "react-native/**",
+ "react",
+ "react/**"
+ ]
+ }
}
+ import {sharedVariable} from “@sharecode/common”;
return (
+ <Text>{sharedVariable}</Text>
)
app > rm -rf node_modules ../../node_modules
app > yarn install // install node_modules
/web/index.js
+ import {sharedVariable} from “@sharecode/common”;
return (
+ <div>{sharedVariable}</div>
)
app > wml ../common ./node_modules/@reactsharecode/common
app > wml start
Please download full source code from KPITENG GitHub.