1.1.0 • Published 6 years ago

rollup-plugin-postcss-modules2 v1.1.0

Weekly downloads
6
License
GPL-3.0
Repository
github
Last release
6 years ago

Build Status

rollup-plugin-postcss-modules

Using rollup-plugin-postcss with postcss-modules is relatively easy, but requires hard to remember boilerplate and there’s only one way to combine them.

Since the boilerplate clutters your rollup.config.js, this plugin wraps the above packages in the one way it makes sense.

Just add some regular PostCSS plugins and be on your way.

Two new options exist:

  • writeDefinitions: true creates .css.d.ts files next to every processed .css file.
  • modules: { ... } can be used to pass options to the intrinsic postcss-modules plugin.

Example

see here for a clonable repo.

rollup.config.js:

import postcss from 'rollup-plugin-postcss-modules'
import typescript from 'rollup-plugin-typescript2'

import autoprefixer from 'autoprefixer'

export default {
	entry: 'src/index.tsx',
	dest: 'dist/bundle.js',
	format: 'iife',
	plugins: [
		postcss({
			extract: true,  // extracts to `${basename(dest)}.css`
			plugins: [autoprefixer()],
			writeDefinitions: true,
			// modules: { ... }
		}),
		typescript(),
	],
}

index.html

<!doctype html>
<script src=dist/bundle.js></script>
<link rel=stylesheet href=dist/bundle.css>

<main id=main></main>

src/index.tsx:

import * as React from 'react'
import * as ReactDOM from 'react-dom'

import MyComponent from './components/my-component'

document.addEventListener('DOMContentLoaded', () => {
    ReactDOM.render(<MyComponent/>, document.querySelector('#main'))
})

src/components/my-component.tsx:

import * as React from 'react'

import style from './my-component.css'

export default class MyClass extends React.Component<{}, {}> {
    render() {
        return <div className={style.myClass} />
    }
}

src/components/my-component.css:

.my-class { ... }
1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago