Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alexzhang1030/unplugin-use-macro


https://github.com/alexzhang1030/unplugin-use-macro

Last synced: 7 days ago
JSON representation

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.