Adding css-modules with a custom Rollup config breaks the build.
See original GitHub issueCurrent Behavior
Create a new project with react template: npx tsdx create mylib
- Add
postcss
plugin and extend Rollup config withtsdx.config.js
yarn add -D rollup-plugin-postcss
const postcss = require('rollup-plugin-postcss');
module.exports = {
rollup(config, options) {
config.plugins.push(
postcss({
modules: true,
})
);
return config;
},
};
- Add a test css-module file
/src/style.module.css
, import and use it in/src/index.tsx
.test {
color: red;
}
import * as React from 'react';
import styles from './style.module.css';
// Delete me
export const Thing = () => {
return <div className={styles.test}>the snozzberries taste like snozzberries</div>;
};
- Build the library
yarn build
The build script exits with this error:
Suggested solution(s)
Apparently, the custom configuration added in tsdx.config.js
is not interpreted and the parser doesn’t seem to know how to manage the .test
css class in style.module.css
.
If you downgrade TSDX to 0.9.3
the build passes.
This issue happens with TSDX >= v0.10.0
Your environment
Software | Version(s) |
---|---|
TSDX | 0.10.5 |
TypeScript | 3.6.4 |
Yarn | 1.19.0 |
Node | v10.15.3 |
Operating System | macOS 10.14.6 |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
How to setup rollup for css modules in TypeScript
I found about a preserveModules flag for the rollup config file from ... import babel from 'rollup-plugin-babel'; import typescript from ...
Read more >How to Bundle JavaScript With Rollup — Step-by- ...
Learn how to use Rollup as a smaller, more efficient alternative to webpack and Browserify to bundle JavaScript files in this step-by-step tutorial...
Read more >rollup.js
Rollup should typically be used from the command line. ... Import a specific item from a source module, with a custom name assigned...
Read more >rollup-plugin-postcss
Start using rollup-plugin-postcss in your project by running `npm i ... rollup.config.js ... Or with custom options for `postcss-modules`.
Read more >Creating a React Component Library using Rollup, Typescript ...
This will generate and place the types of our components within our build folder. Feel free to adjust this config to your liking....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
do you mind retrying with v0.11? we reverted the change to @wessberg/rollup-plugin-ts. reopen if still persists.
I can confirm @sw-yx, upgrading to v0.11 solves the issue. Thanks.