Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexzhang1030/unplugin-use-macro
https://github.com/alexzhang1030/unplugin-use-macro
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/alexzhang1030/unplugin-use-macro
- Owner: alexzhang1030
- License: mit
- Created: 2022-12-24T09:53:51.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-24T15:05:17.000Z (almost 2 years ago)
- Last Synced: 2024-10-10T22:43:37.839Z (about 1 month ago)
- Language: TypeScript
- Size: 117 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# unplugin-use-macro
> **Note**
> This project is in alpha stage, and is not ready for production use.[![NPM version](https://img.shields.io/npm/v/unplugin-use-macro?color=a1b858&label=)](https://www.npmjs.com/package/unplugin-use-macro)
## Install
```bash
pnpm i -D unplugin-use-macro
```Vite
```ts
// vite.config.ts
import UseMacro from 'unplugin-use-macro/vite'export default defineConfig({
plugins: [
UseMacro({/* options */}),
],
})
```Example: [`playground/`](./playground/)
Rollup
```ts
// rollup.config.js
import UseMacro from 'unplugin-use-macro/rollup'export default {
plugins: [
UseMacro({ /* options */ }),
],
}
```
Webpack
```ts
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-use-macro/webpack')({ /* options */ })
]
}
```
Nuxt
```ts
// nuxt.config.js
export default {
buildModules: [
['unplugin-use-macro/nuxt', { /* options */ }],
],
}
```> This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)
Vue CLI
```ts
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-use-macro/webpack')({ /* options */ }),
],
},
}
```
esbuild
```ts
// 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.
```ts
// 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
```js
((arg) => {
return arg
})('hello Macro')
```## Type
```json5
// 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.