Is there a way to set up a project in VS Code that can use npm modules?
Ideally the web pages would be in the root directory or a subdirectory and can share class and value objects with Node.js.
But for example, I want to import a client side js library (saved from npm) into my JavaScript class.
import { pixi } from "/pixi.js";
var app = new PixiJS();
app.draw()
Normally doing the above breaks the build/compiler (if the web pages are in a sub folder like public
).
But if I copy the npm module JS code into that subdirectory and then import from that it works. So that is why I want to have the web pages in the root directory.
I know there is Webpack and other bundlers but I don’t know if I like the idea of having all the JS bundled into a single JS file. Currently, web inspector tools use the TS files.
It seems to me that if TypeScript can set a export directory for the web project or JS it should be able to export the npm modules. But when I use a export directory a bunch of things break (browser can’t find the TS files, other errors).
I have a related question that describes my overall goal: How to setup a nodejs project so client side node modules resolve in the browser
1