|
|
|
|
|
by lioeters
1427 days ago
|
|
Searching Bun's documentation (currently the long README on GitHub) for "macro", I only see a brief usage example as part of the build configuration, like: [macros]
# Remap any import like this:
# import {graphql} from 'react-relay';
# To:
# import {graphql} from 'macro:bun-macro-relay';
react-relay = { "graphql" = "bun-macro-relay" }
..Or as a transpiler option: const transpiler = new Bun.Transpiler({
loader: "tsx",
define: {
"process.env.NODE_ENV": JSON.stringify("development"),
user_undefined: "undefined",
},
platform: "bun",
macro: {
inline: {
whatDidIPass: `${import.meta.dir}/inline.macro.js`,
},
react: {
bacon: `${import.meta.dir}/macro-check.js`,
},
},
});
..But not within the transpiled code itself.Ooh, hold on - there's more in /test/macro. Here's hello-fetch-macro.tsx. import { fetchSync } from "macro:./fetchSync.tsx";
const synchronousFetch = fetchSync(`https://example.com`);
console.log(synchronousFetch);
Looks like the special import syntax converts the function to run at build time.https://github.com/oven-sh/bun/blob/c3bf97002d6f0b117060dabf... |
|