Skip to content

Commit 25897e6

Browse files
committed
Fix babel not working with typescript project referencing
Note: the critical code is NOT mine; see facebook/create-react-app#6799 (comment).
1 parent ef372a8 commit 25897e6

26 files changed

+100
-76
lines changed

.shared/.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,6 @@ dist
115115
.yarn/install-state.gz
116116
.pnp.*
117117

118-
# ts built js files
119-
/built-src
118+
# ts built files
119+
*.js
120+
*.d.ts

.shared/index.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.shared/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./src/types";

.shared/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"name": "opal-shared",
33
"version": "1.0.0",
44
"scripts": {
5-
"start": "tsc -w"
5+
"start": "tsc -b -w"
66
}
77
}

.shared/src/types.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.shared/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"esModuleInterop": true,
99
"allowSyntheticDefaultImports": true,
1010
"strictNullChecks": true,
11+
"declaration": true,
12+
"declarationMap": true,
1113
"strictFunctionTypes": true,
1214
"forceConsistentCasingInFileNames": true,
1315
"noFallthroughCasesInSwitch": true,
@@ -16,7 +18,5 @@
1618
"emitDecoratorMetadata": true,
1719
"experimentalDecorators": true,
1820
"resolveJsonModule": true,
19-
"outDir": "built-src"
2021
},
21-
"include": ["src"]
2222
}

client/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@
2121
npm-debug.log*
2222
yarn-debug.log*
2323
yarn-error.log*
24+
25+
# ts built js files
26+
/built-src

client/config-overrides.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Code by @DakotaLarson on Github.
3+
* See https://github.com/facebook/create-react-app/issues/6799#issuecomment-570081122
4+
*/
5+
6+
const {
7+
override,
8+
removeModuleScopePlugin,
9+
getBabelLoader,
10+
} = require("customize-cra");
11+
const path = require("path");
12+
13+
console.log("f");
14+
15+
const addShared = (config) => {
16+
console.log(config);
17+
const loader = getBabelLoader(config, false);
18+
const sharedPath = path
19+
.normalize(path.join(process.cwd(), "../.shared/src/types"))
20+
.replace(/\\/g, "\\");
21+
22+
loader.include = [loader.include, sharedPath];
23+
return config;
24+
};
25+
26+
module.exports = override(addShared, removeModuleScopePlugin());

client/package-lock.json

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
"@types/react-dom": "^16.9.10",
1010
"@types/react-router-dom": "^5.1.6",
1111
"@types/recompose": "^0.30.7",
12+
"customize-cra": "^1.0.0",
1213
"firebase": "^7.23.0",
1314
"katex": "^0.12.0",
1415
"react": "^16.13.1",
16+
"react-app-rewired": "^2.1.8",
1517
"react-dom": "^16.13.1",
1618
"react-feather": "^2.0.8",
1719
"react-router-dom": "^5.2.0",
@@ -21,9 +23,9 @@
2123
"typescript": "^4.1.3"
2224
},
2325
"scripts": {
24-
"start": "react-scripts start",
25-
"build": "react-scripts build",
26-
"test": "react-scripts test",
26+
"start": "react-app-rewired start",
27+
"build": "react-app-rewired build",
28+
"test": "react-app-rewired test",
2729
"eject": "react-scripts eject"
2830
},
2931
"proxy": "https://localhost:2718",

0 commit comments

Comments
 (0)