如何在 Nuxt 3.x 中使用 Pug?
How to use Pug in Nuxt 3.x?
如果我们通过 npx nuxi init nuxt3-app
创建 Nuxt 3 应用程序并将 app.vue
的内容从
更改
<template>
<div>
<NuxtWelcome />
</div>
</template>
到
<template lang="pug">
div
NuxtWelcome
</template>
我们会得到
ERROR [unhandledRejection] Cannot find module 'pug' 17:05:54
Require stack:
- D:\IntelliJ IDEA\Experiments\nuxt3-app\node_modules\@vue\compiler-sfc\dist\compiler-sfc.cjs.js
- D:\IntelliJ IDEA\Experiments\nuxt3-app\node_modules\vue\compiler-sfc\index.js
- D:\IntelliJ IDEA\Experiments\nuxt3-app\node_modules\@vitejs\plugin-vue\dist\index.js
我没想到内置 Pug 支持,但也没有提示如何提供。
AFAIK 默认 Nuxt 3 安装程序使用 Vite 而不是 Webpack。也许答案在 Vite setup overriding 中?
对于 Vite:
- 安装 vite-plugin-pug。 Vite 自动检测。
- 重新启动应用构建
注意this bug。
如果我们通过 npx nuxi init nuxt3-app
创建 Nuxt 3 应用程序并将 app.vue
的内容从
<template>
<div>
<NuxtWelcome />
</div>
</template>
到
<template lang="pug">
div
NuxtWelcome
</template>
我们会得到
ERROR [unhandledRejection] Cannot find module 'pug' 17:05:54
Require stack:
- D:\IntelliJ IDEA\Experiments\nuxt3-app\node_modules\@vue\compiler-sfc\dist\compiler-sfc.cjs.js
- D:\IntelliJ IDEA\Experiments\nuxt3-app\node_modules\vue\compiler-sfc\index.js
- D:\IntelliJ IDEA\Experiments\nuxt3-app\node_modules\@vitejs\plugin-vue\dist\index.js
我没想到内置 Pug 支持,但也没有提示如何提供。
AFAIK 默认 Nuxt 3 安装程序使用 Vite 而不是 Webpack。也许答案在 Vite setup overriding 中?
对于 Vite:
- 安装 vite-plugin-pug。 Vite 自动检测。
- 重新启动应用构建
注意this bug。