Skip to content

Commit 70b0a09

Browse files
authored
Use babel transpiler for TS in CRA-TS template (codesandbox#1536)
* Use babel transpiler for TS in CRA-TS template * Remove an integration test
1 parent 6c84b82 commit 70b0a09

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed
Binary file not shown.

packages/app/integration-tests/tests/sandboxes.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const SANDBOXES = [
1717
'lp5rjr0z4z',
1818
'nOymMxyY',
1919
'y26rj99yov', // react transition
20-
{ id: 'X6npLXPRW', threshold: 0.05 }, // react-table
2120
'6w66jzw3mn', // material-design & preact
2221
'4j7m47vlm4', // material-ui
2322
'github/cssinjs/egghead/tree/master/from-sass-to-cssinjs/templates-and-variables', // postcss egghead

packages/app/src/sandbox/eval/presets/create-react-app-typescript/index.js

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Preset from '../';
22

33
import stylesTranspiler from '../../transpilers/style';
4-
import typescriptTranspiler from '../../transpilers/typescript';
54
import jsonTranspiler from '../../transpilers/json';
65
import rawTranspiler from '../../transpilers/raw';
76
import babelTranspiler from '../../transpilers/babel';
@@ -20,13 +19,60 @@ export default function initialize() {
2019
{ transpiler: stylesTranspiler },
2120
]);
2221

23-
preset.registerTranspiler(module => /\.tsx?$/.test(module.path), [
24-
{ transpiler: typescriptTranspiler },
25-
]);
26-
27-
preset.registerTranspiler(module => /\.jsx?$/.test(module.path), [
28-
{ transpiler: babelTranspiler },
29-
]);
22+
const babelOptions = {
23+
isV7: true,
24+
compileNodeModulesWithEnv: true,
25+
config: {
26+
plugins: [
27+
'transform-flow-strip-types',
28+
'transform-destructuring',
29+
'babel-plugin-macros',
30+
['proposal-class-properties', { loose: true }],
31+
['proposal-object-rest-spread', { useBuiltIns: true }],
32+
[
33+
'transform-runtime',
34+
{
35+
corejs: false,
36+
helpers: true,
37+
regenerator: true,
38+
},
39+
],
40+
'syntax-dynamic-import',
41+
],
42+
presets: [
43+
[
44+
'env',
45+
{
46+
// We want Create React App to be IE 9 compatible until React itself
47+
// no longer works with IE 9
48+
targets: {
49+
ie: 9,
50+
},
51+
// Users cannot override this behavior because this Babel
52+
// configuration is highly tuned for ES5 support
53+
ignoreBrowserslistConfig: true,
54+
// If users import all core-js they're probably not concerned with
55+
// bundle size. We shouldn't rely on magic to try and shrink it.
56+
useBuiltIns: false,
57+
// Do not transform modules to CJS
58+
modules: false,
59+
},
60+
],
61+
'react',
62+
'typescript',
63+
],
64+
},
65+
};
66+
preset.registerTranspiler(
67+
module => /\.(t|j)sx?$/.test(module.path) && !module.path.endsWith('.d.ts'),
68+
[
69+
{
70+
transpiler: babelTranspiler,
71+
options: babelOptions,
72+
},
73+
],
74+
true
75+
);
3076

3177
preset.registerTranspiler(module => /\.json$/.test(module.path), [
3278
{ transpiler: jsonTranspiler },

packages/app/src/sandbox/eval/presets/create-react-app/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ export default function initialize() {
7979
},
8080
};
8181
preset.registerTranspiler(
82-
module => /\.(t|j)sx?$/.test(module.path),
82+
module =>
83+
/\.(t|j)sx?$/.test(module.path) && !module.path.endsWith('.d.ts'),
8384
[
8485
{
8586
transpiler: babelTranspiler,

0 commit comments

Comments
 (0)