Created
December 22, 2020 19:55
-
-
Save niranjannitesh/c73dfaa4659825b41cfec91d2deac845 to your computer and use it in GitHub Desktop.
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 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