21 lines
622 B
JavaScript
21 lines
622 B
JavaScript
|
|
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([]),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
]));
|
||
|
|
},
|
||
|
|
},
|
||
|
|
};
|
||
|
|
};
|