Translate specific packages in node_modules to es5
P粉481366803
P粉481366803 2023-08-17 21:55:01
0
1
608
<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>
P粉481366803
P粉481366803

reply all(1)
P粉786800174

You can add specific overrides in include in tsconfig.

"include": [
  "src/**/*",
  "node_modules/foo/index.ts",
  "node_modules/bar/quux.baz.mjs"
]

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:

{
  test: /\.(js|ts)$/,
  exclude: /node_modules\/(?!(foo|bar)\/).*/, // 这一行

However, if you want autofill, using @babel/preset-env with a Browserslist string is probably the best option.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template