Skip to content

Instantly share code, notes, and snippets.

@niranjannitesh
Created December 22, 2020 19:55
Show Gist options
  • Save niranjannitesh/c73dfaa4659825b41cfec91d2deac845 to your computer and use it in GitHub Desktop.
Save niranjannitesh/c73dfaa4659825b41cfec91d2deac845 to your computer and use it in GitHub Desktop.
const fs = require('fs')
module.exports = function (babel) {
return {
visitor: {
ExportNamedDeclaration(path, state) {
const filename = state.file.opts.filename;
const name = path.node.declaration.declarations[0].id.name
if (name !== 'php') return
const code = path.node.declaration.declarations[0].init.quasis[0].value.raw
const phpFilePath = filename.replace(/^.*[\\\/]/, '').replace('.js', '.php')
fs.writeFileSync(`./build/${phpFilePath}`, code)
},
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment