Created
November 16, 2021 15:03
Babel plugin for debugging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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