Skip to content

Commit

Permalink
Add postcss-d-ts to CRA as aside
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Kirmas committed Mar 18, 2021
1 parent 768d627 commit f9f07f0
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 117 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ build

*.tgz
package/
postcss-output
2 changes: 2 additions & 0 deletions __recipes__/create-react-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

postcss-output
213 changes: 103 additions & 110 deletions __recipes__/create-react-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions __recipes__/create-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"@types/node": "^12.20.6",
"@types/react": "^17.0.3",
"@types/react-dom": "^17.0.2",
"postcss-cli": "^8.3.1",
"npm-run-all": "^4.1.5",
"postcss-cli": "^7.1.2",
"postcss-d-ts": "file:../../package",
"react": "^17.0.1",
"react-dom": "^17.0.1",
Expand All @@ -19,8 +20,12 @@
"web-vitals": "^1.1.1"
},
"scripts": {
"postcss-d-ts": "postcss 'src/**/*.css' --use postcss-d-ts/dist/7 --dir postcss-output",
"postcss": "postcss 'src/**/*.{css,scss,sass}' --dir postcss-output",
"postcss:dev": "npm run postcss -- --watch",
"start:both": "npm-run-all -p postcss:dev start",
"start": "react-scripts start",
"build": "react-scripts build",
"build": "npm run postcss && react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"prebuild": "npm run ci && npm install ../../package/",
Expand Down
19 changes: 19 additions & 0 deletions __recipes__/create-react-app/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
!process.env.NODE_ENV && (process.env.NODE_ENV = "development")

const craConfig = require("react-scripts/config/webpack.config")()

const {oneOf} = craConfig.module.rules.find(({oneOf}) => oneOf)

const {use} = oneOf.find(({use}) => use && use
.some(({options: {ident}}) => ident === "postcss")
)

const {options} = use.find(({options: {ident}}) => ident === "postcss")
const plugins = options.plugins()

plugins.push(require("postcss-d-ts/dist/7"))

module.exports = {
...options,
plugins
}
File renamed without changes.
11 changes: 11 additions & 0 deletions __recipes__/create-react-app/src/App.module.css.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** Generated by [postcss-d-ts](https://github.com/askirmas/postcss-d-ts) */
declare const identifiersMap: CssIdentifiersMap

export default identifiersMap

export type CssIdentifiersMap = {
"App": string|undefined
"App-header": string|undefined
"App-link": string|undefined
"App-logo": string|undefined
}
10 changes: 5 additions & 5 deletions __recipes__/create-react-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React from 'react';
import logo from './logo.svg';
import './App.css';
import styles from './App.module.css';

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<div className={styles.App}>
<header className={styles["App-header"]}>
<img src={logo} className={styles["App-logo"]} alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
className={styles["App-link"]}
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
Expand Down

0 comments on commit f9f07f0

Please sign in to comment.