'Webpack exclude library from bundle

I'm trying to bundle the project with webpack 5. There is a problem with dynamic import, and I can't fix it, so I decided to exclude this library from the bundle, and then it works fine. But, In the production version, I'm removing node_modules because it's running on lambda.

So here is a question: Can we exclude library from bundle but use it without node_modules? If yes, how we can achieve this?

For example, copy the library from node_modules to the dist folder and then change import * from "library_name" to point to the import * from "./dist/library_name" directory.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source