TypeScript Bundle
The TypeScript RPC library can be bundled and published to NPM with pre-filled package.json
and README.md
files with bundle
command:
npx vovk bundle
Internally the bundling is made executing the following steps:
- It generates a client into
tmp_prebundle
directory (configured withconfig
) using ts template. - Uses tsdown APIβ to bundle the generated client into a few compiled files at
dist
directory. - Generates
package.json
andREADME.md
files from packageJson and readme templates. - Deletes the
tmp_prebundle
directory.
After running the command, you will find the following files in the dist
directory:
- index.cjs
- index.d.cts
- index.mjs
- index.d.mts
- schema.cjs
- schema.d.cts
- package.json
- README.md
That can be published with:
npm publish dist
Configuring the Bundle
The bundling can be configured by adding the bundle
object in the config file:
/** @type {import('vovk').VovkConfig} */
const config = {
bundle: {
tsClientOutDir: 'tmp_prebundle', // default
dontDeleteTsClientOutDirAfter: false, // default
requires: {
readme: '.', // default
packageJson: '.', // default
myTemplate: './foo', // custom template
},
package: {}, // package.json content
readme: {}, // README.md content
tsdownBuildOptions: {
outDir: 'dist', // default
},
},
};
export default config;
tsClientOutDir
or --ts-client-out-dir
flag
The tsClientOutDir
is the directory where the TypeScript client will be generated before bundling. It defaults to tmp_prebundle
.
dontDeleteTsClientOutDirAfter
or --dont-delete-ts-client-out-dir-after
flag
If set to true
, the tsClientOutDir
will not be deleted after bundling. This can be useful for debugging or further modifications. Defaults to false
.
requires
The requires
object allows you to specify extra templates that will be rendered and copied to the dist
directory. The keys are the template names, and the values are the resulting paths, relative to the bundle output directory.
package
The package
object allows you to define the content of the generated package.json
and README.md
(for document title, description and version). You can specify fields like name
, version
, description
, etc. By default it uses the root package.json
file properties, extended with package option of composed client.
readme
The readme
object allows you to define the content of the generated README.md
. Currently only banner
value is supported. By default uses readme option of composed client.
tsdownBuildOptions
Any options that can be passed to tsdownβ build
function. The options are outlined in the tsdown documentationβ.
Troubleshooting
At some cases you might get the following error:
[plugin rolldown-plugin-dts:generate]
RollupError: tmp_prebundle/index.ts(17,14): error TS2742: The inferred type of 'XxxRPC' cannot be named without a reference to '../node_modules/vovk/mjs/client/types'. This is likely not portable. A type annotation is necessary.
In order to fix it, you can add the following line to compilerOptions.paths
in your tsconfig.json
:
{
"compilerOptions": {
"paths": {
"vovk/*": ["../node_modules/vovk/*"]
}
}
}