node.jsloopbackjs

Manually created subfolder from /src is missing in /dist when building


I created a subfolder in /src called /libs. When I run npm run build, the subfolder isn't included in /dist.

I'm assuming that I have to modify a build script? If so, which file would that be?

Edit #1

This all stems from trying to require a custom module located in src/libs from my controller. I've tried various patterns: ../libs/module_name, ./libs/module_name. The only way to have it work was to hard code the path from the root (i.e. /home/me/app/src/libs/module_name).

If I do: console.log(__dirname) in the controller that is attempting to require the module from /lib, I see a reference to /dist. I went looking into /dist and /libs wasn't there.


Solution

  • lb-tsc is a thin wrapper for TypeScript compiler (tsc), you can find the source in loopback-next:packages/build/bin/compile-package.js

    Among other options, it provides a new flag --copy-resources to copy non-TypeScript files from src to dist. I think it may work equally well (if not better) as your cp -r solution.

    "scripts": {
        ...
        "build": "lb-tsc es2017 --outDir dist --copy-resources"
        ...
    }
    

    Personally, I would use a different solution: