Skip to content

Instantly share code, notes, and snippets.

@dac09
Created November 16, 2021 15:03
Show Gist options
  • Save dac09/a3748b14fd0e4ac215e084fd8ff1133c to your computer and use it in GitHub Desktop.
Save dac09/a3748b14fd0e4ac215e084fd8ff1133c to your computer and use it in GitHub Desktop.
Babel plugin for debugging
const template = require('@babel/template').default
module.exports = {
plugins: [
[
function debugPlugin({ types }) {
return {
name: 'debug-plugin',
visitor: {
Program(p, options) {
const buildLogger = template(`
console.log('Dannys babel plugin says hello', FILE_NAME)
`)
const ast = buildLogger({
FILE_NAME: types.stringLiteral(options.filename),
})
console.log('Transforming:', options.filename)
console.log('-'.repeat(20))
p.node.body.unshift(ast)
},
},
}
},
undefined,
'debug-plugin-danny-logger',
],
],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment