javascriptnode.jstypescriptnpm

Is there a way I can use npm with the direct source code rather than minified/bundled code?


I want to use npm and JavaScript (or TypeScript) 3rd party libraries directly from the source code.

For example, in Python, I can go directly into the source code make changes in them and see it directly reflected in my application. I want the same functionality with JavaScript because this helps me understand what's going on with my 3rd party dependencies.


Solution

  • I have found the easiest way is to:

    1. Fork the npm module's repo (most modules have a link to the source code.)
    2. Make the desired changes to the package.
    3. (Some packages may require a build step. Check the readme/package.json)
    4. Add the module via your fork's github url (instead of the package name)

    https://gitpkg.vercel.app/ helps get the appropriate url to npm install for a certain folder/commit.


    It is also possible to monkey-patch the module from the node_modules folder.

    The main property of package.json determines what is loaded when a package is imported (is it from a built file in a dist folder? Just a JS source file?)

    Editing the files in node_modules will have immediate effect, but may be overridden by future npm commands. Something like patch-package may help make your changes more permanent.


    Related references: