VScode debug EJS files of HEXO theme? #5161
-
How does one debug a Hexo theme in VScode? At the moment, I'm doing this "old school" with a bunch of Supposedly, there is a way to do this in VScode by adding an "attach to node" process in the debugger via the {
"type": "node",
"name": "Hexo Theme inspector",
"request": "attach",
"program": "${workspaceFolder}/node_modules/hexo-cli/bin/hexo",
"args": [
"server",
"-p 4001",
"--debug"
],
"runtimeExecutable": "node",
"runtimeArgs": [
"--inspect=4001"
],
"processId": "${command:PickProcess}",
"protocol": "inspector",
"address": "127.0.0.1",
"port": 4001,
"restart": true,
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/**/*.js"
],
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}",
"cwd": "${workspaceFolder}",
"console": "internalConsole"
}, After running VScode will stop the code and step through the nodeJS files within the ReferenceRelated |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
As I currently understand the HEXO architecture, it's simply not possible to use breakpoints within an EJS template file. As a best practice, one should restrict the template files to only the visual elements needed to construct the webpage. All logic more complex than a simple variable call ( Complex code that doesn't build the visual HTML elements should be a helper. Such helpers can be debugged in VScode with breakpoints as it is processed through an "runtimeArgs": [
"--inspect-brk=4001",
"--experimental-modules",
"--preserve-symlinks"
], |
Beta Was this translation helpful? Give feedback.
As I currently understand the HEXO architecture, it's simply not possible to use breakpoints within an EJS template file.
As a best practice, one should restrict the template files to only the visual elements needed to construct the webpage. All logic more complex than a simple variable call (
<%= myVar %>
) or simple function call (<%- myFunc() %>
) should be moved to a Hexo helper ƒunction in your theme'sscript/helpers/
folder.Complex code that doesn't build the visual HTML elements should be a helper. Such helpers can be debugged in VScode with breakpoints as it is processed through an
eval()
function by HEXO. Once the JS file is loaded, VScode will bound the breakpoint and enable you t…