use babel source instead of babel packages (@babel/*)

358 Views Asked by At

I would like to embed babel in my project using source version (github.com/babel) instead of packaged version (npm @babel/*) in order to benefits of a better (webpack) tree-shaking (@babel/* is cjs whereas github.com/babel is mjs/ts/flow).

I use 3rd-party libraries that require node_modules/@babel/* and I would like to configure TypeScript to make it use node_modules/babel/packages/babel-*/src instead.

I am aware that there is no module alias in TypeScript.

I tried with compilerOptions.paths with no success :

    paths: {
        '@babel/code-frame': ['babel/packages/babel-code-frame/src'],
        '@babel/...': ['babel/packages/babel-.../src'],
        ...
    }

Is there a trick to make any require to @babel/* to point to babel/packages/babel-*/src ?

note: in my webpack configuration file, I use:

resolve: {
    alias: {
        '@babel/code-frame': 'babel/backages/babel-code-frame/src',

and I'm looking for the equivalent for typescript.

Related context: https://github.com/FranckFreiburger/vue3-sfc-loader/issues/7

(feel free to ask me more details if necessary)

Edit: I think the resolution of this question is doomed to failure since (AFAIK) TypeScript cannot import flow files. My only option is to wait the resolution of Migrate Babel from Flow to TypeScript PR.

0

There are 0 best solutions below