Skip to content

Commit 9addb7e

Browse files
committed
chore: add postcss support
1 parent 1a367ee commit 9addb7e

12 files changed

+1003
-20
lines changed

.eslintrc.js

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module.exports = {
2020
'plugin:react/recommended',
2121
'standard',
2222
'prettier',
23-
'prettier/@typescript-eslint',
2423
'plugin:prettier/recommended',
2524
'plugin:@typescript-eslint/eslint-recommended',
2625
],

Globals.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module '*.module.css';

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ A template to create a react component / library with Typescript.
99
- React
1010
- Typescript
1111
- Rollup
12+
- Css Modules
1213
- Jest with code coverage report
1314
- `Typedoc` for API documentation
1415
- `standard-version` ready

jest.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@ module.exports = {
22
preset: 'ts-jest',
33
testEnvironment: 'jsdom',
44
testPathIgnorePatterns: ['example', 'node_modules'],
5+
setupFiles: ['@testing-library/react/dont-cleanup-after-each'],
6+
moduleNameMapper: {
7+
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
8+
'<rootDir>/__mocks__/fileMock.js',
9+
'\\.(scss|sass|css)$': 'identity-obj-proxy',
10+
},
511
};

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@
6262
"eslint-plugin-standard": "^4.1.0",
6363
"gh-pages": "^3.1.0",
6464
"husky": "^6.0.0",
65+
"identity-obj-proxy": "^3.0.0",
6566
"jest": "^26.6.3",
6667
"lint-staged": "^10.5.4",
68+
"postcss": "^8.2.13",
6769
"prettier": "^2.2.1",
6870
"prompt": "^1.1.0",
6971
"react": "^17.0.2",
@@ -74,6 +76,7 @@
7476
"rollup-plugin-json": "^4.0.0",
7577
"rollup-plugin-node-resolve": "^5.2.0",
7678
"rollup-plugin-peer-deps-external": "^2.2.4",
79+
"rollup-plugin-postcss": "^4.0.0",
7780
"rollup-plugin-sourcemaps": "^0.6.3",
7881
"rollup-plugin-terser": "^7.0.2",
7982
"rollup-plugin-typescript2": "^0.30.0",

rollup.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import commonjs from 'rollup-plugin-commonjs';
22
import json from 'rollup-plugin-json';
33
import resolve from 'rollup-plugin-node-resolve';
4+
import postcss from 'rollup-plugin-postcss';
45
import external from 'rollup-plugin-peer-deps-external';
56
import sourceMaps from 'rollup-plugin-sourcemaps';
67
import { terser } from 'rollup-plugin-terser';
@@ -36,6 +37,9 @@ export default {
3637
},
3738
plugins: [
3839
external(),
40+
postcss({
41+
modules: true,
42+
}),
3943
// Allow json resolution
4044
json(),
4145
// Compile TypeScript files

src/__tests__/index.test.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { render } from '@testing-library/react';
2+
import '@testing-library/jest-dom';
23
import Main from '../index';
34

45
describe('My Component', () => {

src/index.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useEffect } from 'react';
2+
import styles from './styles.module.css';
23

34
interface Props {
45
message?: string;
@@ -11,7 +12,9 @@ function Greeting(props: Props) {
1112
console.log('Incoming message: ', props.message);
1213
}, [props.message]);
1314

14-
return <div>{props.message ?? 'No Message'}</div>;
15+
return (
16+
<div className={styles.container}>{props.message ?? 'No Message'}</div>
17+
);
1518
}
1619

1720
export default Greeting;

src/styles.module.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.container {
2+
display: flex;
3+
}

tools/init.ts

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
/* eslint-disable @typescript-eslint/no-var-requires */
1313
/* eslint-disable @typescript-eslint/no-explicit-any */
1414

15+
if (process.env['RTL_SKIP_POSTINSTALL']) {
16+
console.log('Skipping post-install process...');
17+
process.exit(0);
18+
}
19+
1520
const { basename, resolve } = require('path');
1621
const replace = require('replace-in-file');
1722
const { readFileSync, writeFileSync } = require('fs');

tsconfig.json

+22-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
"compilerOptions": {
33
"target": "es5",
44
"module": "ES6",
5-
"lib": ["ES2017", "ES7", "ES6", "DOM"],
5+
"lib": [
6+
"ES2017",
7+
"ES7",
8+
"ES6",
9+
"DOM"
10+
],
611
"declaration": true,
712
"declarationDir": "dist",
813
"outDir": "dist",
@@ -16,8 +21,21 @@
1621
"moduleResolution": "node",
1722
"resolveJsonModule": true,
1823
"jsx": "react-jsx",
19-
"baseUrl": "./src"
24+
"baseUrl": "./src",
25+
"plugins": [
26+
{
27+
"name": "typescript-plugin-css-modules"
28+
}
29+
],
2030
},
21-
"include": ["src/**/*"],
22-
"exclude": ["node_modules", "dist", "src/**/*.spec.tsx", "src/**/*.test.tsx"]
31+
"include": [
32+
"src/**/*",
33+
"Globals.d.ts"
34+
],
35+
"exclude": [
36+
"node_modules",
37+
"dist",
38+
"src/**/*.spec.tsx",
39+
"src/**/*.test.tsx"
40+
]
2341
}

0 commit comments

Comments
 (0)