From 17f0ea6bd6f062a952a98e04f6d7349784e1946f Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sat, 7 Dec 2019 12:18:01 +0000 Subject: [PATCH 1/2] docs: add warning for programmatic usage closes #219 --- docs/guide/setup.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/guide/setup.md b/docs/guide/setup.md index 4f0178b0..7bd0cbe9 100644 --- a/docs/guide/setup.md +++ b/docs/guide/setup.md @@ -71,6 +71,22 @@ and create a **`tsconfig.json`** file : Check official [TypeScript documentation](https://www.typescriptlang.org/docs/handbook/compiler-options.html) to learn about the different compiler options. ::: +::: warning + +If you are using Nuxt programmatically with a custom server framework, note that you will need to ensure that you wait for Nuxt to be ready before building: + +```js + +// Make sure to wait for Nuxt to load @nuxt/typescript-build before proceeding +await nuxt.ready() +... +if (config.dev) { + const builder = new Builder(nuxt) + await builder.build() +} +``` +::: + That's it, you're all set to use TypeScript in your **layouts**, **components**, **plugins** and **middlewares**. You can check the [**CookBook**](../cookbook/components/) section to get some TypeScript recipes for your Nuxt project. From 78768729e49d92904f9c6274af2fb44b2c4edcb0 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sat, 7 Dec 2019 12:50:29 +0000 Subject: [PATCH 2/2] docs: add section on programmatic runtime usage closes #193 --- docs/guide/runtime.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/guide/runtime.md b/docs/guide/runtime.md index 321ce215..d54537c4 100644 --- a/docs/guide/runtime.md +++ b/docs/guide/runtime.md @@ -42,3 +42,25 @@ All you need to do is update your **package.json** file: ::: You can now use TypeScript for **nuxt.config** file, local **modules** and **serverMiddlewares**. + +::: warning + +`@nuxt/typescript-runtime` does not support programmatic usage (as it extends `@nuxt/cli`). + +Advanced users might try adding the following code to your server entrypoint (see [source](https://github.com/nuxt/typescript/blob/master/packages/typescript-runtime/src/index.ts)): + +```js +import { register } from 'ts-node' + +register({ + project: 'tsconfig.json', + compilerOptions: { + module: 'commonjs' + } +}) +``` + +However, this is **not recommended or supported**. +::: + +