unplugin-typesugar
v0.1.0
Published
Bundler integrations for typesugar (Vite, Webpack, esbuild, Rollup)
Downloads
119
Maintainers
Readme
unplugin-typesugar
Bundler integrations for typesugar macro expansion.
Overview
unplugin-typesugar provides plugins for popular bundlers to process typesugar macros during your build. Powered by unplugin for maximum compatibility.
Installation
npm install unplugin-typesugar
# or
pnpm add unplugin-typesugarVite
// vite.config.ts
import typesugar from "unplugin-typesugar/vite";
export default {
plugins: [typesugar()],
};Webpack
// webpack.config.js
const typesugar = require("unplugin-typesugar/webpack").default;
module.exports = {
plugins: [typesugar()],
};esbuild
// build.js
import esbuild from "esbuild";
import typesugar from "unplugin-typesugar/esbuild";
await esbuild.build({
entryPoints: ["src/index.ts"],
plugins: [typesugar()],
bundle: true,
outfile: "dist/index.js",
});Rollup
// rollup.config.js
import typesugar from "unplugin-typesugar/rollup";
export default {
input: "src/index.ts",
plugins: [typesugar()],
output: {
file: "dist/index.js",
format: "esm",
},
};Configuration
All plugins accept the same options:
interface TypeMacroPluginOptions {
/** Enable verbose logging */
verbose?: boolean;
/** Include/exclude patterns */
include?: string | string[];
exclude?: string | string[];
/** Custom macro modules to load */
macroModules?: string[];
}Example with Options
// vite.config.ts
import typesugar from "unplugin-typesugar/vite";
export default {
plugins: [
typesugar({
verbose: true,
include: ["src/**/*.ts"],
exclude: ["**/*.test.ts"],
}),
],
};How It Works
The integration plugins:
- Intercept TypeScript files during the build
- Create a TypeScript program with the typesugar transformer
- Expand macros at compile time
- Emit transformed code to the bundler
This means macros are fully expanded before your code reaches the bundler's optimization pipeline.
API Reference
Exports
unplugin-typesugar/vite— Vite pluginunplugin-typesugar/webpack— Webpack pluginunplugin-typesugar/esbuild— esbuild pluginunplugin-typesugar/rollup— Rollup pluginunplugin-typesugar— Core unplugin factory
Types
interface TypeMacroPluginOptions {
verbose?: boolean;
include?: string | string[];
exclude?: string | string[];
macroModules?: string[];
}License
MIT
