Skip to content
This repository was archived by the owner on Jul 29, 2025. It is now read-only.

Commit bcb2ade

Browse files
add
1 parent 2b70e1c commit bcb2ade

File tree

3 files changed

+119
-23
lines changed

3 files changed

+119
-23
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
"@babel/preset-react": "^7.12.7",
3737
"@babel/preset-typescript": "^7.13.0",
3838
"@rollup/plugin-babel": "^5.2.1",
39+
"@rollup/plugin-commonjs": "^17.1.0",
40+
"@rollup/plugin-node-resolve": "^11.2.0",
3941
"babel-plugin-source-map-support": "^2.1.3",
4042
"prop-types": "^15.7.2",
4143
"react": "^17.0.1",

src/transpiler/transpiler.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import Path from 'path';
22

33
import { rollup } from 'rollup';
4+
import commonjs from '@rollup/plugin-commonjs';
5+
import resolve from '@rollup/plugin-node-resolve';
46
import babel from '@rollup/plugin-babel';
57

68
import { getStatsInDir } from '../utils';
79
import { TranspileFilesOptions } from '../types';
810

911
const ROOT_DIR = Path.resolve(__dirname, '../..');
12+
const extensions = ['.js', '.jsx', '.cjs', '.tsx'];
1013

1114
/**
1215
* Transpile files in a given directory (and sub directory if recursive option are passed) and write it to an output directory,
@@ -18,7 +21,7 @@ const ROOT_DIR = Path.resolve(__dirname, '../..');
1821
*/
1922
export async function transpileFiles(directory: string, outputDir: string, options?: TranspileFilesOptions) {
2023
const { files, dirs } = await getStatsInDir(directory);
21-
24+
2225
if (files.length) {
2326
/**
2427
* WHEN ADDING PLUGINS to transform the input keep in mind that
@@ -31,10 +34,17 @@ export async function transpileFiles(directory: string, outputDir: string, optio
3134
input: files,
3235
onwarn: ()=>{},
3336
plugins: [
37+
// Allows node_modules resolution
38+
resolve({ extensions }),
39+
40+
// // Allow bundling cjs modules. Rollup doesn't understand cjs
41+
// commonjs(),
42+
43+
// Compile TypeScript/JavaScript files
3444
babel({
3545
cwd: ROOT_DIR,
3646
babelHelpers: "bundled",
37-
extensions: ['.js', '.jsx', '.cjs', '.tsx'],
47+
extensions,
3848
presets: [
3949
"@babel/preset-env",
4050
"@babel/preset-typescript",

0 commit comments

Comments
 (0)