feat(nuxt3): allow disabling vue type shims (#2773)

This commit is contained in:
Daniel Roe 2022-01-19 18:10:38 +00:00 committed by GitHub
parent 74ce059d6f
commit f219f635ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 8 deletions

View File

@ -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.

View File

@ -1,5 +1,4 @@
import './augments'
import './shims'
// eslint-disable-next-line
export * from '../index'

View File

@ -1,6 +0,0 @@
// https://github.com/vitejs/vite/blob/main/packages/create-vite/template-vue-ts/src/env.d.ts
declare module '*.vue' {
import { DefineComponent } from '@vue/runtime-core'
const component: DefineComponent<{}, {}, any>
export default component
}

View File

@ -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

View File

@ -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',

View File

@ -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
}