一覧へ戻る
Comandeer/rollup-plugin-macros(新しいタブで開きます)
主要言語: JavaScript
- star 数
- 3
- watcher 数
- 1
- fork 数
- 1
- issue 数
- 0
- 最終更新
- 2023/10/08
主要言語: JavaScript
Experimental port of Bun macros into Rollup.js.
npm install @comandeer/rollup-plugin-macros --save-dev
Add it to your Rollup.js configuration:
import macros from '@comandeer/rollup-plugin-macros'; export default { input: './src/index.js', output: [ { file: './dist/bundle.js', format: 'es' } ], plugins: [ macros() ], }; export default config;
Now you can create a module with a macro, e.g. random.js:
function random() { return Math.random(); } export { random };
And then import it in your code with appropriate import attribute:
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:
console.log(0.7507075485199182);
I've written a detailed article in Polish about inner workings of this package.
See LICENSE file for details.