From 6411a497c64a0b3ddc91fc576ab136f9ef4e3928 Mon Sep 17 00:00:00 2001 From: Comandeer Date: Sun, 25 Jun 2023 22:02:17 +0200 Subject: [PATCH] docs(readme): update usage instructions --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index 8ad7afe..8610615 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,32 @@ export default { export default config; ``` +Now you can create a module with a macro, e.g. `random.js`: + +```javascript +function random() { + return Math.random(); +} + +export { random }; +``` + +And then import it in your code with appropriate import attribute: + +```javascript +import { random } from './random.js' with { type: 'macro' }; +// or using the older syntax +// import { random } from './random.js' assert { type: 'macro' }; + +console.log( random() ); +``` + +After bundling the code with Rollup the import will be removed and the `random()` call replaced with an actual value returned by the macro: + +```javascript +console.log(0.7507075485199182); +``` + ## How does it work? ## License