Skip to content

Commit 0cca4aa

Browse files
Initial commit
1 parent 3fe8dda commit 0cca4aa

File tree

7 files changed

+3656
-0
lines changed

7 files changed

+3656
-0
lines changed

.babelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"presets": [["env", {
3+
"targets": {
4+
"node": 4
5+
}
6+
}]]
7+
}

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.swp
2+
*~
3+
*.iml
4+
.*.haste_cache.*
5+
.DS_Store
6+
.idea
7+
npm-debug.log
8+
node_modules
9+
dist

.npmignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.swp
2+
*~
3+
*.iml
4+
.*.haste_cache.*
5+
.DS_Store
6+
.idea
7+
.babelrc
8+
.eslintrc
9+
npm-debug.log
10+
lib

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# `react-app-rewire-styled-components-typescript`
2+
3+
Add the [`typescript-plugin-styled-components`](https://github.com/Igorbek/typescript-plugin-styled-components) to your `create-react-app` app via [`react-app-rewired`](https://github.com/timarney/react-app-rewired) and [`react-scripts-ts`](https://github.com/wmonk/create-react-app-typescript).
4+
5+
## Installation
6+
7+
```sh
8+
npm install --save react-app-rewire-styled-components-typescript
9+
10+
# alternatively if you have yarn installed
11+
yarn add react-app-rewire-styled-components-typescript
12+
```
13+
14+
## Usage
15+
16+
In the `config-overrides.js` you created for `react-app-rewired` add this code:
17+
18+
```JS
19+
const rewireStyledComponentsTypescriptPlugin = require('react-app-rewire-styled-components-typescript');
20+
21+
module.exports = function override(config, env) {
22+
config = rewireStyledComponentsTypescriptPlugin(config, env);
23+
24+
return config;
25+
}
26+
```

package.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "react-app-rewire-styled-components-typescript",
3+
"version": "1.0.0",
4+
"description": "A plugin to add typescript-plugin-styled-components to a create-react-app with react-scripts-ts",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/AustinBrunkhorst/react-app-rewire-styled-components-typescript.git"
8+
},
9+
"main": "dist/index.js",
10+
"license": "Unlicense",
11+
"scripts": {
12+
"precommit": "lint-staged",
13+
"prebuild": "rimraf dist",
14+
"build": "babel src --out-dir dist --ignore '*.test.js'",
15+
"test": "jest src",
16+
"prettier": "prettier --write --single-quote --trailing-comma es5 'src/**/*.js'"
17+
},
18+
"lint-staged": {
19+
"*.js": [
20+
"prettier --write --single-quote --trailing-comma es5",
21+
"git add"
22+
]
23+
},
24+
"dependencies": {
25+
"typescript-plugin-styled-components": "^0.0.6"
26+
},
27+
"peerDependencies": {
28+
"react-app-rewired": "^1.5.2"
29+
},
30+
"devDependencies": {
31+
"babel-cli": "6.x.x",
32+
"babel-preset-env": "^1.7.0",
33+
"husky": "^0.13.4",
34+
"jest": "19.x.x",
35+
"lint-staged": "^3.6.1",
36+
"prettier": "^1.3.1",
37+
"rimraf": "^2.6.2"
38+
}
39+
}

src/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { getLoader, loaderNameMatches } = require('react-app-rewired');
2+
3+
const { createTransformer } = require('typescript-plugin-styled-components');
4+
const styledComponentsTransformer = createTransformer();
5+
6+
const tsLoaderMatcher = rule => loaderNameMatches(rule, 'ts-loader');
7+
const getTsLoader = rules => getLoader(rules, tsLoaderMatcher);
8+
9+
const rewireStyledComponentsTypescriptPlugin = (config, _env) => {
10+
const tsLoader = getTsLoader(config.module.rules);
11+
12+
if (!tsLoader) {
13+
console.log('ts-loader not found');
14+
15+
return config;
16+
}
17+
18+
tsLoader.options.getCustomTransformers = () => ({
19+
before: [styledComponentsTransformer],
20+
});
21+
22+
return config;
23+
};
24+
25+
module.exports = rewireStyledComponentsTypescriptPlugin;

0 commit comments

Comments
 (0)