Babel Plugin
The Babel plugin writes extracted CSS to a file on disk instead of a virtual module. Use it with webpack, Parcel, or any Babel pipeline.
Install
Section titled “Install”bun add typewritingclassbun add -d typewritingclass-babel typewritingclass-compilerpnpm add typewritingclasspnpm add -D typewritingclass-babel typewritingclass-compilernpm install typewritingclassnpm install -D typewritingclass-babel typewritingclass-compilerConfigure
Section titled “Configure”{ "plugins": [ ["typewritingclass-babel", { "outputFile": "dist/twc.css", "strict": true }] ]}Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
outputFile | string | "twc.css" | Path for the extracted CSS file. |
strict | boolean | true | Error on non-static cx() args. See Strict Mode. |
Including the CSS
Section titled “Including the CSS”Since CSS is written to disk, include it via HTML or a bundler import:
<link rel="stylesheet" href="/dist/twc.css" />import './dist/twc.css'webpack example
Section titled “webpack example”module.exports = { module: { rules: [ { test: /\.tsx?$/, use: 'babel-loader' }, { test: /\.css$/, use: ['style-loader', 'css-loader'] }, ], },}Comparison with Vite and esbuild
Section titled “Comparison with Vite and esbuild”| Feature | Vite | esbuild | Babel |
|---|---|---|---|
| CSS output | Virtual module | Virtual module | File on disk |
| HMR | Yes | Via watch | No |
| Import | virtual:twc.css | virtual:twc.css | <link> or bundler |
| Best for | Vite projects | esbuild projects | webpack/Parcel/CRA |
For new projects, the Vite plugin is recommended.