0.0.6 • Published 1 year ago

unplugin-use-macro v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

unplugin-use-macro

Note This project is in alpha stage, and is not ready for production use.

NPM version

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.

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago