Skip to content

Commit

Permalink
Explicitly specify ts and tsx extensions in babel options (#96)
Browse files Browse the repository at this point in the history
* fix: explicitly specify ts and tsx extensions in babel options

rollup-plugin-typescript2 transpiles the code but doesn't change the
file extensions. Files with ts and tsx extentions aren't processed by
Babel by default so we need to add those extensions to the babel config.

* Patch/extend @babel/core types
  • Loading branch information
jakegavin authored and jaredpalmer committed May 10, 2019
1 parent 517b8fa commit 6512b46
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/createRollupConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEFAULT_EXTENSIONS } from '@babel/core';
import { safeVariableName, safePackageName, external } from './utils';
import { paths } from './constants';
import { terser } from 'rollup-plugin-terser';
Expand All @@ -14,6 +15,7 @@ const replacements = [{ original: 'lodash', replacement: 'lodash-es' }];

const babelOptions = {
exclude: /node_modules/,
extensions: [...DEFAULT_EXTENSIONS, 'ts', 'tsx'],
plugins: [
'annotate-pure-calls',
'dev-expression',
Expand Down
7 changes: 7 additions & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ declare module 'ora';
declare module 'sade';
declare module 'tiny-glob/sync';
declare module 'ansi-escapes';

// Patch Babel
// @see line 226 of https://unpkg.com/@babel/core@7.4.4/lib/index.js
declare module '@babel/core' {
export const DEFAULT_EXTENSIONS: string[];
}

// Rollup plugins
declare module '@jaredpalmer/rollup-plugin-preserve-shebang';
declare module 'rollup-plugin-babel';
Expand Down

0 comments on commit 6512b46

Please sign in to comment.