Translate specific packages in node_modules to es5
P粉481366803
2023-08-17 21:55:01
<p>I'm making an Angular 12 (IE compatible) project where some of my dependencies in node_modules are non-es5. </p>
<p>In my understanding, <code>tsc</code> will not do any processing on node_modules, but will only retrieve <code>main</code> from <code>angular.json</code> ;Option starts evaluation. </p>
<p>While looking for options on how to do this, I saw a lot of suggestions to use babel, but I'm not sure</p>
<ol>
<li><p>Should I mix babel with tsc.
Or do I do away with <code>tsc</code> and just use babel via custom-webpack? </p>
</li>
<li><p>As I understand it, in all transpilations, the transpiled code goes into an output directory, but since I need to transpile the js files in node_modules, the output of these files should just replace them in Original files in node_modules? How do we achieve this? </p>
</li>
</ol><p><br /></p>
You can add specific overrides in
include
in tsconfig.But when you package for the client, you usually don't include the dependencies as separate scripts, but let the packaging tool decide where to put them. You didn't mention what packaging tool you're currently using, but if you set
allowJS: true
, Babel is not required - for example, the relevant changes to the Webpack config would be:However, if you want autofill, using
@babel/preset-env
with a Browserslist string is probably the best option.