idyll-lang / idyll

Create explorable explanations and interactive essays.
http://idyll-lang.org/
MIT License
2.01k stars 87 forks source link

Allow babelConfig to be extended by user (or support compileLibs everywhere) #667

Open s3ththompson opened 3 years ago

s3ththompson commented 3 years ago

Is your feature request related to a problem? Please describe. I can't build a component that imports an untranspiled ES module from a dependency. Three notoriously ships its examples (including OrbitControls, etc.) as untranspiled ESM. It looks like the undocumented compileLibs option is respected in src/pipeline/bundle-js but not in src/node-config.

Describe the solution you'd like Ideally, idyll would allow extending the default babelConfig (perhaps similarly to how Next.js extends webpack config). This would allow userland solutions to my issue (transpiling an ES module from a dependency) but also other customization that might otherwise require adding and supporting additional flags.

Describe alternatives you've considered Even if the compileLibs option was extended to turn on node_modules transpilation everywhere, the solution would be inefficient as transpiling all dependencies is expensive. In my case, it is only one dependency (three) which requires transpilation.

Additional context I also tried to submit a simple PR to make src/node-config respect compileLibs by having babel-register compile node_modules, but couldn't get the approach to work as idyll has other dependencies in node_modules that break when run through babel-register.

s3ththompson commented 3 years ago

FWIW, I needed to make this change to src/node-config to solve my problem:

require('babel-register')({
  presets: ['env', 'stage-2', 'react'],
   babelrc: false,
-  only: isWindows ? undefined : new RegExp(`(${transformFolders.join('|')})`)
+  ignore: [/node_modules\/(?!three)/],
});

It looks like the problem is made a bit more difficult by the fact that there are two layers of babel transformation happening? Does babel-register not respect other babelConfig?