I have been following this article:
How to create strongly-typed npm packages
and have been trying to setup my typescript project to publish it to npm.
It all seems to make sense but what is not covered is how to deal with d.ts
files.
My project looks somewhat like this:
src
node
server.ts
browser
client.ts
common
contracts.d.ts
so when I compile this with "declaration": true
and "outDir: "dist"
I get:
dist
node
server.js
server.d.ts
browser
client.js
client.d.ts
both my server.ts
file and client.ts
files have
import {SomeType} from "../common/contracts";
in so when someone else uses this package the typescript compilation will fail as server.d.ts
and client.d.ts
both still have this import.
Node will run fine though as client.js
and server.js
do NOT have this import. tsc
must remove imports of d.ts
files.
What I want to happen is for the contracts.d.ts
file to be copied to the dist folder as part of the build. How do I do that as part of the tsc
build?
Current Workaround
What I am currently doing to get round this is rename my contracts.d.ts
to just contracts.ts
which means that all required files are present in the dist folder but it does mean that both the client and the server are having to load an empty contracts.js
file that only contains
"use strict";
//# sourceMappingURL=contracts.js.map