Registry / web-framework / babel-plugin-twin

babel-plugin-twin

JSON →
library1.1.0jsnpmunverified

Babel plugin to automatically add the tw prop from twin.macro and the css prop from CSS-in-JS libraries without explicit imports. Current stable version is 1.1.0. Updated irregularly as needed. Key differentiator: eliminates the need for `import 'twin.macro'` in every file, streamlining usage with twin.macro for Tailwind CSS in React.

npm install babel-plugin-twin
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TWIN
B
babel-plugin-twin
web-frameworkjavascriptv1.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

babel-plugin-twin
// In babel.config.js module.exports = { plugins: [ "babel-plugin-twin", "babel-plugin-macros", ], };
// Wrong: placing twin after macros module.exports = { plugins: [ "babel-plugin-macros", "babel-plugin-twin", ], };
Plugin must be listed before babel-plugin-macros in the plugins array.
exclude option
// In babel.config.js with exclude module.exports = { plugins: [ ["babel-plugin-twin", { exclude: [/node_modules/] }], "babel-plugin-macros", ], };
// Wrong: comma between plugin and options module.exports = { plugins: [ ["babel-plugin-twin", { exclude: [/node_modules/] }], "babel-plugin-macros", ], };
Exclude is an array of regex patterns.
debug option
// In babel.config.js with debug module.exports = { plugins: [ ["babel-plugin-twin", { debug: true }], "babel-plugin-macros", ], };
Debug prints feedback during transformation.

Installation and basic configuration to use tw and css props without imports.

// Install // npm i -D babel-plugin-twin // babel.config.js module.exports = { plugins: [ "babel-plugin-twin", "babel-plugin-macros", ], }; // Now you can use tw prop without import // Component.jsx const Component = () => <div tw="block" />; // Also css prop works via your CSS-in-JS library const StyledDiv = () => <div css={`background-color: blue;`} />;
Debug
Known issues
gotchaPlugin must be placed before babel-plugin-macros in the plugins array.
fix
Reorder plugins array so that 'babel-plugin-twin' comes before 'babel-plugin-macros'.
affects: all
deprecatedNo known deprecations in this version.
breakingNo breaking changes reported in recent versions.
Errors
Common errors & fixes
Error: Cannot find module 'babel-plugin-twin'
Plugin not installed or not in node_modules.
fix
Run npm install -D babel-plugin-twin or yarn add -D babel-plugin-twin.
ReferenceError: tw is not defined
babel-plugin-twin not correctly configured in babel config.
fix
Ensure babel-plugin-twin is added before babel-plugin-macros in plugins array.
babel-plugin-macros: Could not resolve macro 'twin.macro'
twin.macro not installed or not configured.
fix
Install twin.macro: npm install twin.macro. Also ensure babel-plugin-twin is before babel-plugin-macros.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
babel-plugin-macrosrequiredRequired to be present and configured after babel-plugin-twin in babel plugins array for twin.macro to function
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
babel-plugin-twin — npm install babel-plugin-twin · libregistry