I created a new tsconfig.build.json file and extended tsconfig.app.json, seems to work fine:
tsconfig.build.json
{ "extends": "./tsconfig.app.json", "include": ["lib"] }
Also, with the new vite version with tsconfig.app.json, for building type definitions I had to add tsconfigPath:
dts({ include: ['lib'], rollupTypes: true, tsconfigPath: 'tsconfig.app.json' }),
I would suggest this:
Do not include the lib folder in tsconfig.app.json, instead create a tsconfig.lib.json like so:
lib
tsconfig.app.json
tsconfig.lib.json
Then add tsconfig.lib.json to the references array in your tsconfig.json.
references
tsconfig.json
And set the build script to:
"build": "tsc -b ./tsconfig.lib.json && vite build",
I made a branch with the latest vite version (5.4.4 at the time of writing): github.com/receter/my-component-li...
Here is a summary of what I had to change for the building the types:
update to vite-plugin-dts@4
add tsconfig path to dts config
dts({ tsconfigPath: resolve(__dirname, "tsconfig.lib.json"), }),
This outputs types to a lib subfolder in dist. So you need to update your package.json to point to the correct type entry: "./dist/lib/main.d.ts" (or you could use rollupTypes: true)
Also I manually had to install ajv because of an issue: stackoverflow.com/questions/787352...
ajv
In this branch I also use the new package.json exports feature and "self reference" the library in App.tsx.
exports
I will try to find time to update my article accordingly, but for now this branch might help you.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I created a new
tsconfig.build.json
file and extended tsconfig.app.json, seems to work fine:{
"extends": "./tsconfig.app.json",
"include": ["lib"]
}
Also, with the new vite version with tsconfig.app.json, for building type definitions I had to add tsconfigPath:
dts({ include: ['lib'], rollupTypes: true, tsconfigPath: 'tsconfig.app.json' }),
I would suggest this:
Do not include the
lib
folder intsconfig.app.json
, instead create atsconfig.lib.json
like so:Then add
tsconfig.lib.json
to thereferences
array in yourtsconfig.json
.And set the build script to:
I made a branch with the latest vite version (5.4.4 at the time of writing): github.com/receter/my-component-li...
Here is a summary of what I had to change for the building the types:
update to vite-plugin-dts@4
add tsconfig path to dts config
This outputs types to a
lib
subfolder in dist. So you need to update your package.json to point to the correct type entry: "./dist/lib/main.d.ts" (or you could use rollupTypes: true)Also I manually had to install
ajv
because of an issue: stackoverflow.com/questions/787352...In this branch I also use the new package.json
exports
feature and "self reference" the library in App.tsx.I will try to find time to update my article accordingly, but for now this branch might help you.