Skip to content

Commit

Permalink
feat(nuxt3): allow disabling vue type shims (nuxt#2773)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Jan 19, 2022
1 parent 74ce059 commit f219f63
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
16 changes: 16 additions & 0 deletions docs/content/1.getting-started/1.introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,25 @@ Before getting started, please make sure you have installed the recommended setu
* **Node.js**<sup>*</sup> (latest LTS version) 👉 [[Download](https://nodejs.org/en/download/)]
* **Visual Studio Code** 👉 [[Download](https://code.visualstudio.com/)]
* **Volar Extension** 👉 [[Download](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.volar)]
* Either enable [**Take Over Mode**](https://github.com/johnsoncodehk/volar/discussions/471) (recommended)
* ... or add **TypeScript Vue Plugin (Volar)** 👉 [[Download](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.vscode-typescript-vue-plugin)]

<sup>*</sup> If you already have Node.js installed, check with `node --version` that you are using `v14` or `v16`.

::alert{type=info}

If you have enabled **Take Over Mode** or installed the **TypeScript Vue Plugin (Volar)** you can disable generating the shim for `*.vue` files:

```js
export default defineNuxtConfig({
typescript: {
shim: false
}
})
```

::

## Nuxt 3 or Bridge?

Next, decide whether to start from scratch or upgrade an existing Nuxt 2 project.
Expand Down
1 change: 0 additions & 1 deletion packages/nuxt3/src/app/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import './augments'
import './shims'

// eslint-disable-next-line
export * from '../index'
6 changes: 0 additions & 6 deletions packages/nuxt3/src/app/types/shims.d.ts

This file was deleted.

4 changes: 4 additions & 0 deletions packages/nuxt3/src/core/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ async function initNuxt (nuxt: Nuxt) {
nuxt.hook('prepare:types', (opts) => {
opts.references.push({ types: 'nuxt3' })
opts.references.push({ path: resolve(nuxt.options.buildDir, 'plugins.d.ts') })
// Add vue shim
if (nuxt.options.typescript.shim) {
opts.references.push({ path: resolve(nuxt.options.buildDir, 'vue-shim.d.ts') })
}
})

// Init user modules
Expand Down
13 changes: 13 additions & 0 deletions packages/nuxt3/src/core/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ type TemplateContext = {
app: NuxtApp;
}

export const vueShim = {
filename: 'vue-shim.d.ts',
write: true,
getContents: () =>
[
'declare module \'*.vue\' {',
' import { DefineComponent } from \'@vue/runtime-core\'',
' const component: DefineComponent<{}, {}, any>',
' export default component',
'}'
].join('\n')
}

// TODO: Use an alias
export const appComponentTemplate = {
filename: 'app-component.mjs',
Expand Down
9 changes: 8 additions & 1 deletion packages/schema/src/config/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@ export default {
* You can extend generated `.nuxt/tsconfig.json` using this option
* @typedef {Awaited<ReturnType<typeof import('pkg-types')['readPackageJSON']>>}
*/
tsConfig: {}
tsConfig: {},

/**
* Generate a `*.vue` shim.
*
* We recommend instead either enabling [**Take Over Mode**](https://github.com/johnsoncodehk/volar/discussions/471) or adding **TypeScript Vue Plugin (Volar)** 👉 [[Download](https://marketplace.visualstudio.com/items?itemName=johnsoncodehk.vscode-typescript-vue-plugin)].
*/
shim: true
}

0 comments on commit f219f63

Please sign in to comment.