服务器构建默认启用源码映射,开发模式下的客户端构建也默认启用,但您可以在配置中更具体地启用它们。
export default defineNuxtConfig({
// or sourcemap: true
sourcemap: {
server: true,
client: true,
},
})
您可以使用Node inspector用于调试 Nuxt 服务器端。
nuxt dev --inspect
这将以激活调试器的 dev 模式启动 Nuxt。如果一切正常,您的 Chrome 开发者工具上会出现一个 Node.js 图标,您可以连接到调试器。
在开发 Nuxt 应用时,可以在 IDE 中对其进行调试是可行的。
您可能需要使用指向您的网页浏览器的路径来更新下方的配置。有关更多信息,请访问VS Code 关于调试配置的文档.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "client: chrome",
"url": "https://:3000",
// this should point to your Nuxt `srcDir`, which is `app` by default
"webRoot": "${workspaceFolder}/app"
},
{
"type": "node",
"request": "launch",
"name": "server: nuxt",
"outputCapture": "std",
"program": "${workspaceFolder}/node_modules/nuxt/bin/nuxt.mjs",
"args": [
"dev"
],
}
],
"compounds": [
{
"name": "fullstack: nuxt",
"configurations": [
"server: nuxt",
"client: chrome"
]
}
]
}
如果您更喜欢使用您常用的浏览器扩展,请将此添加到上方的 chrome 配置中
"userDataDir": false,
您也可以在 JetBrains IDEs(如 IntelliJ IDEA、WebStorm 或 PhpStorm)中调试您的 Nuxt 应用。
nuxt.run.xml。nuxt.run.xml 文件并粘贴以下调试配置<component name="ProjectRunConfigurationManager">
<configuration default="false" name="client: chrome" type="JavascriptDebugType" uri="https://:3000" useFirstLineBreakpoints="true">
<method v="2" />
</configuration>
<configuration default="false" name="server: nuxt" type="NodeJSConfigurationType" application-parameters="dev" path-to-js-file="$PROJECT_DIR$/node_modules/nuxt/bin/nuxt.mjs" working-dir="$PROJECT_DIR$">
<method v="2" />
</configuration>
<configuration default="false" name="fullstack: nuxt" type="CompoundRunConfigurationType">
<toRun name="client: chrome" type="JavascriptDebugType" />
<toRun name="server: nuxt" type="NodeJSConfigurationType" />
<method v="2" />
</configuration>
</component>
如果您有其他 IDE 并希望贡献示例配置,请随时打开一个 PR (Pull Request)!