11import Path from 'path' ;
22
33import { rollup } from 'rollup' ;
4+ import commonjs from '@rollup/plugin-commonjs' ;
5+ import resolve from '@rollup/plugin-node-resolve' ;
46import babel from '@rollup/plugin-babel' ;
57
68import { getStatsInDir } from '../utils' ;
79import { TranspileFilesOptions } from '../types' ;
810
911const 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 */
1922export 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