Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 836
TechFanDan Avatar asked Oct 28 '25 00:10

TechFanDan


1 Answers

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:

  • use src only for TypeScript files to be compiled
  • put JavaScript sources and other files into a different directory, e.g. lib (instead of src/lib).
like image 58
Miroslav Bajtoš Avatar answered Oct 29 '25 15:10

Miroslav Bajtoš



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!