unplugin-use-macro
v0.0.6
Published
Register macro and use
Downloads
3
Readme
unplugin-use-macro
Note This project is in alpha stage, and is not ready for production use.
Install
pnpm i -D unplugin-use-macro
// vite.config.ts
import UseMacro from 'unplugin-use-macro/vite'
export default defineConfig({
plugins: [
UseMacro({/* options */}),
],
})
Example: playground/
// rollup.config.js
import UseMacro from 'unplugin-use-macro/rollup'
export default {
plugins: [
UseMacro({ /* options */ }),
],
}
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-use-macro/webpack')({ /* options */ })
]
}
// nuxt.config.js
export default {
buildModules: [
['unplugin-use-macro/nuxt', { /* options */ }],
],
}
This module works for both Nuxt 2 and Nuxt Vite
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-use-macro/webpack')({ /* options */ }),
],
},
}
// esbuild.config.js
import { build } from 'esbuild'
import UseMacro from 'unplugin-use-macro/esbuild'
build({
plugins: [UseMacro()],
})
Usage
Define a macro and then use it after defined.
// Define by using `useMacro`
useMacro('myMacro', (arg) => {
return arg
})
// Using by `label` statement, but will be compiled
// `$` suffix is necessary
myMacro$: {
'Hello Macro'
}
Compile To
((arg) => {
return arg
})('hello Macro')
Type
// tsconfig.json
{
"compilerOptions": {
// ...other options
"types": [
"unplugin-use-macro/macro"
// other types
]
}
}
Known Issues
1. HMR
This stage not handle HMR
, so will not update when you change the macro body.