A collection of awesome babel macros and related resources
param.macro
: Partial application syntax and lambda parameters for JavaScript, inspired by Scala's_
and Kotlin'sit
ms.macro
: Convert various time formats to millisecondsraw.macro
: Apply webpack'sraw-loader
filesize.macro
: Apply webpack'sfilesize-loader
lqip.macro
: Create LQIP at build-time, similar to webpack'slqip-loader
data-uri.macro
: Convert assets to data URIsregexgen.macro
: Convert set of strings to optimized regular expressiontinker.macro
: Evaluate Laravel code@lingui/macro
: Macro for internationalization in LinguiJSpipeline.macro
: Macro working similarly to the pipeline operatorpaths.macro
: Import paths like__dirname
and__filename
as static valuesfor-own.macro
: Makefor-in
only visit own propertiests-nameof.macro
:nameof
in TypeScriptfiles.macro
: Transform directory into array of file namesflavors.macro
: Build different flavors of an app by manipulating import headers
traph.macro
: Transform Objects easily, leveraging object getters and graphsidx.macro
: Traverse properties on objects and arraysassign.macro
: TranspileObject.assign
-style expressions to direct assignments
preval.macro
: Pre-evaluate code1codegen.macro
: Generate code1import-all.macro
: Import all files that match a glob
scope.macro
: Useful build-time console functionspenv.macro
: Pick specified value or branch according to the build environmentdev-console.macro
: Remove allconsole.log
,console.warn
andconsole.error
calls from production buildsbabel-plugin-trace/macro
: Add labeled statement logging helpers with file and function name prefixinspect.macro
: Log an expression and the result of that expression to the consolerequire-context.macro
: Mock webpack'srequire.context()
Tersus-JSX
: Inspired by AngularJS, ng-if (use tj-if) and ng-repeat (use tj-for) for neater JSX in Reacttagged-translations
: Translate text in React applicationssvgr.macro
: Apply SVGRcss-to-rn.macro
: Convert CSS to React Native style sheethooks.macro
: Automatic React Hooks memoization invalidationinline-mdx.macro
: Convert MDX into inline componentsreact-broker/macros
: Lazy-load React componentsrpi.macro
: Macro forreact-precious-image
react-hot-reload.macro
: Zero configuration Hot Module Replacement for CRAv2mdi-norm/macro
: Embed Material Design system SVG iconsreactive.macro
: Reduce React boilerplate
react-emotion/macro
: Minify and optimize emotion stylesglamorous.macro
: Give your glamorous components a nicedisplayName
for React DevToolsstyled-jsx/macro
: Use styled-jsx'sresolve
tagstyled-components/macro
: Improve the debugging experience and add server-side rendering support to styled-componentsstyled-import/macro
: Lightweight CSS parser for stealing rules from stylesheets, for use with styled-components, React, or anywhere else you might be doing CSS in JS -- especially useful for working with global or 3rd-party stylesheetsunique-classname.macro
: Generate unique className for emotiontailwind.macro
: Use Tailwind with any CSS-in-JS library
graphql.macro
: Compile GraphQL ASTblade.macro
: Generate GraphQL query strings inline and solve the double declaration problem
babel-plugin-macros
usage- Search npm for keyword:babel-plugin-macros to find macros
- Difference between plugins and macros
- Zero-config code transformation with babel-plugin-macros
babel-plugin-macros
usage for macro authors- jamiebuilds/babel-handbook
- Writing custom Babel and ESLint plugins with ASTs
- Code Transformation and Linting
The following projects include babel-plugin-macros
, so macros can be used out of the box without additional configuration:
Contributions welcome! Read the contribution guidelines first.
To the extent possible under law, Jonas Gierer has waived all copyright and related or neighboring rights to this work.