I have a monorepo with the following structure:
repo
packages
native (expo app)
server (express + graphql)
shared (to be shared with the rest)
build
graphql
index.d.ts
index.js
models
user.d.ts
user.js
locale.d.ts
locale.js
index.d.ts
index.js
utils
datetime.d.ts
datetime.js
index.d.ts
index.js
index.d.ts
index.js
src
graphql
index.tsx
models
user.ts
locale.ts
index.ts
utils
datetime.ts
index.ts
index.ts
tsconfig.json
web (nextjs app)
lerna.json
package.json
tsconfig.json
I'm currently using the shared
package like this:
import { getTodayFn, UserClass } from '@repo/shared'
import { getTodayFn } from '@repo/shared/build/utils'
import { UserClass } from '@repo/shared/build/models/user'
But I'd like to be able to import without build
:
import { getTodayFn } from '@repo/shared/utils'
import { UserClass } from '@repo/shared/models/user'
What should I do to achieve what I want?
Configurations:
root/tsconfig.json
:
{
"compilerOptions": {
"sourceMap": true,
"removeComments": false,
"preserveConstEnums": true,
"downlevelIteration": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"allowUnreachableCode": false,
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"pretty": true,
"forceConsistentCasingInFileNames": true
}
}
packages/shared/tsconfig.json
:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"jsx": "react",
"lib": [
"dom",
"esnext"
],
"skipLibCheck": true,
"preserveConstEnums": true,
"rootDir": "./src",
"outDir": "./build",
"declaration": true,
"declarationDir": "./build",
"declarationMap": true,
"baseUrl": "./",
"paths": {
"@lib/*": [
"src/*"
]
}
},
"include": [
"./src/**/*"
],
"exclude": [
"node_modules",
"build"
]
}
packages/shared/package.json
:
{
"name": "@repo/shared",
"license": "MIT",
"version": "1.0.0",
"main": "build/index.js",
"typings": "build/index.d.ts",
"scripts": {
"build": "rimraf build && tsc",
"watch": "tsc -w"
},
"dependencies": {
},
"devDependencies": {
"rimraf": "^2.6.3",
"typescript": "^3.5.3"
}
}