| 1 |
const fs = require("fs"); |
| 2 |
const path = require("path"); |
| 3 |
|
| 4 |
function inlinePlugin(api, { filename }) { |
| 5 |
const { types: t } = api; |
| 6 |
|
| 7 |
const contents = api.cache.using(() => fs.readFileSync(filename, "utf8")); |
| 8 |
api.addExternalDependency(filename); |
| 9 |
|
| 10 |
return { |
| 11 |
visitor: { |
| 12 |
Identifier(path) { |
| 13 |
if (path.node.name === "REPLACE_ME") { |
| 14 |
path.replaceWith(t.stringLiteral(contents)); |
| 15 |
} |
| 16 |
}, |
| 17 |
}, |
| 18 |
}; |
| 19 |
} |
| 20 |
|
| 21 |
module.exports = { |
| 22 |
plugins: [ |
| 23 |
[inlinePlugin, { filename: path.resolve(__dirname, "./file.txt") }], |
| 24 |
], |
| 25 |
}; |