0

I have a tsconfig.json file that contains paths to be used in my typescript and tsconfig-paths-webpack-plugin for webpack's use. However, one of the paths references a shared library located outside of the project directory. When I attempt to bundle the app with webpack, it reaches out and gets the library appropriately and adds it into the bundle. Is there any way to have it not bundle this external module and just have it adjust the require statement when bundling?

I have tried adding a regex to the externals option in webpack like-so and it prevents the modules from being bundled. However, the tsconfig-paths-webpack-plugin doesn't evaluate the import statement and it remains as @libs/[MY_LIB] in the compiled code instead of "../../../libs/[MY_LIB]":

{
   // ...
   externals: [
      NodeExternals(),
      /^@libs.*/
   ],
}

Ultimate Goal

// This is in the typescript
import * as myLib from "@libs/MY_LIB";

// Should become the following
const myLib = require("../../../libs/MY_LIB");
Jake
  • 1
  • 1
  • Why not use npm link instead ? – Guillaume Jasmin Feb 08 '20 at 22:00
  • @GuillaumeJasmin There is a pretty complex Docker Build going on currently that is preventing me from using a proper npm module installation. It would require a decent refactor at the moment to do so. – Jake Feb 12 '20 at 14:12

0 Answers0