Saturday 2 January 2021

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

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).

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)



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

No comments:

Post a Comment