Skip to content

Commit

Permalink
feat: Enable typescript for production builds
Browse files Browse the repository at this point in the history
chore: Remove irrelevant webpack dev server clauses in production build

fix: Test configuration for typescript

chore: Add documentation for using tsconfig.json in client repos

chore: Update tsconfig.json to use noImplicitAny=false for now

chore: Update tsconfig.json libs, and correct exclude list
  • Loading branch information
marlonkeating committed Jan 27, 2023
1 parent efdaf60 commit 6503492
Show file tree
Hide file tree
Showing 9 changed files with 367 additions and 125 deletions.
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ An example module.config.js file looks like the following. You can copy this in
],
};


Steps
~~~~~

Expand Down Expand Up @@ -157,6 +158,14 @@ You may create a `.env.private` with any overrides of the environment settings c

**Note: .env.private should be added to your project's .gitignore so it does not get checked in.**

Local module configuration for TypeScript
-----------------------------------------

#. Copy tsconfig.json into the root of the module
#. Set "rootDir" to the root of the source code folders
#. Set "include" to wildcard patterns specifying the subdirectories/files under rootDir where source code can be found
#. Include any wildcards under rootDir that should be excluded using "exclude"

Development
-----------

Expand Down
4 changes: 3 additions & 1 deletion config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const fs = require('fs');
const { jsWithTs: tsjPreset } = require('ts-jest/presets');

const presets = require('../lib/presets');

Expand Down Expand Up @@ -33,11 +34,12 @@ module.exports = {
'/node_modules/(?!@edx)',
],
transform: {
'^.+\\.[t|j]sx?$': [
'^.+\\.jsx?$': [
'babel-jest',
{
configFile: presets.babel.resolvedFilepath,
},
],
...tsjPreset.transform,
},
};
4 changes: 2 additions & 2 deletions config/webpack.prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ module.exports = merge(commonConfig, {
// The babel-loader transforms newer ES2015+ syntax to older ES5 for older browsers.
// Babel is configured with the .babelrc file at the root of the project.
{
test: /\.(js|jsx)$/,
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules\/(?!@edx)/,
use: {
loader: 'babel-loader',
options: {
configFile: presets.babel.resolvedFilepath,
configFile: presets['babel-typescript'].resolvedFilepath,
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions example/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import config from 'env.config';
import Image from './Image.tsx';
import appleUrl, { ReactComponent as Apple } from './apple.svg';
import appleImg from './apple.jpg';

Expand All @@ -19,6 +20,8 @@ export default function App() {
</ul>
<h2>JSX parsing tests</h2>
<Apple style={{ width: '10rem' }} />
<h2>TSX parsing tests</h2>
<Image src={appleUrl} alt="appleFromTsx" style={{ width: '10rem' }} />
<h2>Asset import tests</h2>
<img src={appleUrl} alt="apple" style={{ width: '10rem' }} />
<img src={appleUrl} alt="apple" style={{ width: '10rem' }} />
Expand Down
11 changes: 11 additions & 0 deletions example/src/Image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, { CSSProperties } from "react";

type ImageProps = {
src: string;
alt?: string;
style?: CSSProperties;
};

export default function Image(props:ImageProps) {
return <img {...props} />;
}
12 changes: 12 additions & 0 deletions example/src/__snapshots__/App.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ exports[`Basic test should render 1`] = `
}
}
/>
<h2>
TSX parsing tests
</h2>
<img
alt="appleFromTsx"
src="icon/mock/path"
style={
Object {
"width": "10rem",
}
}
/>
<h2>
Asset import tests
</h2>
Expand Down
Loading

0 comments on commit 6503492

Please sign in to comment.