Introduction
Installing with uncompiled projects
Learn how to install imaginary-dev
into a project that doesn't use a compiler.
For projects that don't currently use either Babel or tsc
in their build process, you need to add a compiler to the project. There are two strategies we recommend for that: adding the TypeScript compiler or using ts-node
.
Strategy 1: Use the TypeScript compiler
The first way to install imaginary-dev
into an uncompiled project is to turn it in to a TypeScript compiled project. This means you will be adding a build step before running your code (or adding an extra step to your current build). We recommend that you add the TypeScript compiler by following these instructions from Microsoft.
Once you have the TypeScript compiler running in your project, follow the instructions for adding imaginary-dev
to a TypeScript project.
Strategy 2: Use ts-node
The second way to install imaginary-dev
into an uncompiled project is to switch from using node
to using ts-node
to run your application. ts-node
is a package that wraps node and transforms TypeScript at runtime. This strategy can be slower to load files than pre-compiling them with the TypeScript compiler, but it can be easier to integrate, as it doesn't require adding a build step or having a build output folder. Critically, ts-node
can also support compiler plugins like imaginary-dev
.
First, install ts-node
:
npm install --save-dev typescript ttypescript ts-node
Next, use node to create a default tsconfig.json
file:
./node_modules/typescript/bin/tsc --init
Finally, edit your tsconfig.json file to add a plugins
key under compiler-options
and a top-level ts-node
key with the following contents:
{
"compilerOptions": {
// add the following line to compilerOptions
"plugins": [{ "transform": "@imaginary-dev/typescript-transformer" }]
},
// add the following key at top-level
"ts-node": {
"compiler": "ttypescript"
}
}
Now, you should be able to write imaginary functions and run your project with ts-node
rather than node.