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");