Skip to content

Instantly share code, notes, and snippets.

@dac09
Created November 16, 2021 15:03
Show Gist options
  • Select an option

  • Save dac09/a3748b14fd0e4ac215e084fd8ff1133c to your computer and use it in GitHub Desktop.

Select an option

Save dac09/a3748b14fd0e4ac215e084fd8ff1133c to your computer and use it in GitHub Desktop.

Revisions

  1. dac09 created this gist Nov 16, 2021.
    31 changes: 31 additions & 0 deletions babel.config.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    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',
    ],
    ],
    }