Skip to content

Commit

Permalink
feat: add typescript support for dev config (#262)
Browse files Browse the repository at this point in the history
Adds a new `babel-typescript` preset.
  • Loading branch information
viktorrusakov authored Oct 21, 2022
1 parent 9dab55c commit 3a415fc
Show file tree
Hide file tree
Showing 5 changed files with 350 additions and 234 deletions.
5 changes: 5 additions & 0 deletions config/babel-typescript.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const config = require('./babel.config');

config.presets.push('@babel/preset-typescript');

module.exports = config;
5 changes: 3 additions & 2 deletions config/webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,20 @@ module.exports = merge(commonConfig, {
},
resolve: {
alias: aliases,
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
module: {
// Specify file-by-file rules to Webpack. Some file-types need a particular kind of loader.
rules: [
// 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,
// Caches result of loader to the filesystem. Future builds will attempt to read
// from the cache to avoid needing to run the expensive recompilation process
// on each run.
Expand Down
7 changes: 7 additions & 0 deletions lib/presets.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ const babelPreserveModules = new ConfigPreset({
searchFilepaths,
});

const babelTypescript = new ConfigPreset({
defaultFilename: 'babel-typescript.config.js',
searchFilenames: ['babel-typescript.config.js', '.babelrc', '.babelrc.js', 'babel.config.js'],
searchFilepaths,
});

const eslint = new ConfigPreset({
defaultFilename: '.eslintrc.js',
searchFilenames: ['.eslintrc', '.eslintrc.js'],
Expand Down Expand Up @@ -48,6 +54,7 @@ module.exports = {
babel,
babelPreserveModules,
'babel-preserve-modules': babelPreserveModules,
'babel-typescript': babelTypescript,
eslint,
jest,
webpack,
Expand Down
Loading

0 comments on commit 3a415fc

Please sign in to comment.