Created
November 16, 2021 15:03
-
-
Save dac09/a3748b14fd0e4ac215e084fd8ff1133c to your computer and use it in GitHub Desktop.
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