0.13.0 • Published 22 days ago

unplugin-macros v0.13.0

Weekly downloads
-
License
MIT
Repository
github
Last release
22 days ago

unplugin-macros npm jsr

Unit Test

Macros are a mechanism for running JavaScript functions at bundle-time. The value returned from these functions or variables are directly inlined into your bundle.

Installation

# npm
npm i -D unplugin-macros

# jsr
npx jsr add -D @unplugin/macros
// vite.config.ts
import Macros from 'unplugin-macros/vite'

export default defineConfig({
  plugins: [Macros()],
})

// rollup.config.js
import Macros from 'unplugin-macros/rollup'

export default {
  plugins: [Macros()],
}

Requires esbuild >= 0.15

// esbuild.config.js
import { build } from 'esbuild'

build({
  plugins: [require('unplugin-macros/esbuild')()],
})

// webpack.config.js
module.exports = {
  /* ... */
  plugins: [require('unplugin-macros/webpack')()],
}

Usage

// main.js
import { getRandom, buildTime } from './macros' with { type: 'macro' }

getRandom() // Will be replaced with a random number at build time
buildTime // Will be replaced with the timestamp at the build time
// macros.js
export function getRandom() {
  return Math.random()
}
export const buildTime = Date.now()

See more in Bun Macros.

TypeScript

Import Attributes syntax is supported in TypeScript >= 5.3, but you can replace with keyword with assert, which is supported in TypeScript >= 4.5.

ESLint

ESLint is not supported Import Attributes syntax yet, but you can use @babel/eslint-parser or @typescript-eslint/parser.

Options

Refer to docs.

Thanks

Thanks to Bun Macros.

Sponsors

License

MIT License © 2023-PRESENT 三咲智子

0.13.0

22 days ago

0.12.0

22 days ago

0.12.1

22 days ago

0.11.0

2 months ago

0.10.1

2 months ago

0.10.2

2 months ago

0.10.3

2 months ago

0.9.3

2 months ago

0.10.0

2 months ago

0.9.2

4 months ago

0.9.0

6 months ago

0.9.1

5 months ago

0.8.3

8 months ago

0.8.2

8 months ago

0.8.1

8 months ago

0.8.0

8 months ago

0.7.0

9 months ago

0.6.0

10 months ago

0.5.2

10 months ago

0.5.1

10 months ago

0.5.0

10 months ago

0.4.2

10 months ago

0.4.1

10 months ago

0.4.0

10 months ago

0.3.1

10 months ago

0.3.0

11 months ago

0.2.0

11 months ago

0.1.0

11 months ago

0.0.1

11 months ago