Skip to content

Instantly share code, notes, and snippets.

@robdodson
Last active May 12, 2020 06:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robdodson/897af7ab00019364fe0589e7c8999ae0 to your computer and use it in GitHub Desktop.
Save robdodson/897af7ab00019364fe0589e7c8999ae0 to your computer and use it in GitHub Desktop.
module.exports = function(eleventyConfig) {
eleventyConfig.addFilter('debug', function(...args) {
debugger;
});
}
{
"name": "my project",
"scripts": {
"debug:eleventy": "node --inspect-brk ./node_modules/.bin/eleventy",
}
}
{{ data | debug }}
@jonsage
Copy link

jonsage commented May 8, 2020

How does this work please? I'm being naive but I can't get it to do anything :/

@robdodson
Copy link
Author

Running node with node --inspect-brk will put it into debug mode. If you have a page that uses the debug filter, then eleventy will halt execution when it processes that page. Whatever data you pass to that debug filter will show up when the debugger hits the debug statement on line 3 of .eleventy.js.

This post is a bit old but it explains the process: https://medium.com/@paul_irish/debugging-node-js-nightlies-with-chrome-devtools-7c4a1b95ae27

If you haven't used the node debugger before I'd suggest first creating a plain index.js file, and writing a few statements and adding a debugger statement in there to halt execution. See if you can get that working with node --inspect or node --inspect-brk. Once that seems to do what you expect, then try with eleventy. hope that helps!

@robdodson
Copy link
Author

robdodson commented May 12, 2020

oh maybe read this too: https://itnext.io/the-absolute-easiest-way-to-debug-node-js-with-vscode-2e02ef5b1bad
I forgot that I have the extension they mention in that post installed so my VS Code automatically connects the debugger if I start node with the --inspect-brk flag using VS Code's integrated terminal.

@jonsage
Copy link

jonsage commented May 12, 2020

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment