bstein-dev-home/testing/frontend/babel-plugin-import-meta-env.cjs

21 lines
622 B
JavaScript
Raw Permalink Normal View History

module.exports = function importMetaEnvPlugin({ types: t }) {
return {
name: "atlas-import-meta-env-test-plugin",
visitor: {
MetaProperty(path) {
if (path.node.meta.name !== "import" || path.node.property.name !== "meta") return;
path.replaceWith(t.objectExpression([
t.objectProperty(
t.identifier("env"),
t.logicalExpression(
"||",
t.memberExpression(t.identifier("globalThis"), t.identifier("__ATLAS_IMPORT_META_ENV__")),
t.objectExpression([]),
),
),
]));
},
},
};
};