Code: Select all
react-native-builder-bob
Code: Select all
yarn add file:./my-library-v1.0.0.tgz
Code: Select all
yarn add ./my-library-v1.0.0.tgz
< /code>
< /li>
[*] Die Build -Ausgabestruktur sieht so aus:
lib/
├── commonjs/
│ ├── index.js
│ ├── components/
│ ├── constants/
│ ├── helpers/
│ ├── types/
├── module/
│ ├── index.js
│ ├── components/
│ ├── constants/
│ ├── helpers/
│ ├── types/
├── typescript/
├── commonjs/src/index.d.ts
├── module/src/index.d.ts
< /code>
< /li>
mein [b]package.json
Code: Select all
"main": "./lib/commonjs/index.js",
"module": "./lib/module/index.js",
"types": "./lib/typescript/commonjs/src/index.d.ts",
"exports": {
".": {
"import": {
"types": "./lib/typescript/module/src/index.d.ts",
"default": "./lib/module/index.js"
},
"require": {
"types": "./lib/typescript/commonjs/src/index.d.ts",
"default": "./lib/commonjs/index.js"
}
}
}
< /code>
< /li>
< /ul>
[b] ✅ Was funktioniert < /strong> < /h3>
Wenn ich den Import manuell schreibe, funktioniert alles fein: < /strong>
🚨 Was funktioniert nicht < /strong> < /h3>
VSCODE schlägt den Import mit CMD +. < /code> (Schnellfix) < /strong> nicht vor:
[code]react/jsx-no-undef
< /code>
< /li>
Es werden keine automatischen Importvorschläge angezeigt. Alles: < /strong>
rm -rf node_modules && yarn install
Code: Select all
⇧ Shift + ⌘ Cmd + P
[*] Sicherstellen, dass Index.d.ts korrekt lokalisiert ist in lib/Typscript/CommonJS/src/src/index.d.ts . class = "Lang-Bash PrettyPrint-Override">
Code: Select all
yarn add my-library@file:./my-library-v1.0.0.tgz
Code: Select all
import MyComponent from "my-library/lib/commonjs";
< /code>
→ [b] Dies funktioniert, aber es ist nicht der richtige Weg, um das Paket zu importieren. Fehlt mir etwas in package.json
Code: Select all
cmd + .