node.js - 在 Docker 中调试服务器上的 nuxtjs .vue 文件
问题描述
我目前有一个 nuxt 应用程序设置作为我使用 Docker 托管的通用应用程序。我几乎一切正常,调试器在遍历中间件和 api 调用时附加并找到局部变量很好,但是在调试文件中的asyncData
方法时,.vue
我看不到任何局部变量,我的断点不断移动到该.catch
行:
在当前上下文中,我还得到了一堆其他随机的东西,在这种情况下是“模块”??
我已将此行添加到我的nuxt.config.js
文件中,以确保它使用正确的源映射:
/*
** Build configuration
*/
build: {
/*
** You can extend webpack config here
*/
extend(config, ctx) {
console.log(`IsClient: ${ctx.isClient}`);
console.log(`isDev: ${ctx.isDev}`);
if (ctx.isDev) {
config.devtool = ctx.isClient ? 'source-map' : 'inline-source-map'
}
}
}
这也是我的.vscode
配置:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Docker: Attach to Node",
"type": "node",
"request": "attach",
"remoteRoot": "/usr/share/nginx/app",
"port": 9229,
"address": "localhost",
"localRoot": "${workspaceFolder}/app",
"protocol": "inspector",
"restart": true,
"sourceMaps": true
}
]
}
另外,这是我用来启动容器的命令:
node --inspect=0.0.0.0:9229 \
./node_modules/.bin/nuxt \
& nginx -g "daemon off;" \
我已经尝试了很多不同的方法,包括使用 babel-register 并使用 babel-node 启动它,因为它已被转译,但这些方法都不起作用。
我在这里有什么遗漏吗?.vue
创建通用应用程序时,我们可以不调试服务器上的文件吗?
更新
我切换到 Webstorm,无论出于何种原因,调试都完美无缺。我想这就是使用 IDE 和文本编辑器之间的区别。
解决方案
attach
当您的 nuxt 应用程序已经启动时,vs 代码检查器。
要查看服务器端发生了什么,vs code 必须启动您的 nuxt 应用程序。
将此脚本添加到您的 package.json:
...
scripts: {
"dev": "nuxt,
"dev-debug": "node --inspect node_modules/.bin/nuxt",
...
}
...
在 .vscode 配置或 .vscode/launch.json 中:
"configurations": [{
"type": "node",
"request": "launch",
"name": "Launch nuxt",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run",
"dev-debug"
],
"port": 9229
},
...
nuxt.config.js
最后,当我们在开发模式下运行时,扩展构建以添加源映射,并确保客户端和服务器的类型正确。
build: {
extend(config, ctx) {
if (ctx.isDev) {
config.devtool = ctx.isClient ? 'source-map' : 'inline-source-map'
}
}
}
它在本地主机上对我有用,但我不确定它是否与远程根一起工作......
此外,这不是一个完美的解决方案。我有时看到断点从不同的行跳转。我认为这是因为 vs 代码无法处理源代码和内联源代码中的相同行。
替代方式:
要仅调试单个文件组件 ( .vue
) 的 javascript,可以将 javascript 部分提取到外部.js
文件中,然后使用<script src="./path-to-js"></script>
.
推荐阅读
- java - Java 不停止发送电子邮件 (JAvaMail Eclipse)
- javascript - VuePress 扩展 markdown-it 目录
- python-3.x - Python tkinter:如何使条目值更新变量?
- r - 在数据框中的每一列中将每个值向前移动一步
- python - Python:在循环写入时扩展文件内容
- vuetify.js - 将卡片容器放在其他容器上 Vuetify VueJs
- python - python - 如何用python中不同列表中的字符替换列表中的字符
- javascript - 如何拆分数据以仅获取特定部分 - JavaScript
- swift - 为什么带有 setFrame 的 NSWindow 的帧值会发生变化
- python - 使用特征子集运行预测