1

I made a library with angular 6 and there are assets into this library.
When I install this library in another app and build that app, assets of library don't exist into production building files. I don't want to add library assets in angular.json of the app.

How can I load assets of library in building?

Thanks in advance.

Morteza Ebrahimi
  • 740
  • 1
  • 8
  • 20

1 Answers1

3

According to this documentation

npm supports the "scripts" property of the package.json file, for the following scripts:
install, postinstall: Run AFTER the package is installed.

So in your package.json file of your own library, add a section like this:

package.json:

{
  "name": "app",
  "version": "0.0.0",
  "scripts": {
    "install": "run some script in any language like node-js or python,..."
  }
  // ...
}

Then you can write a script file (for example in node-js) to do some jobs like copying your assets to wherever you want, compiling some files, etc.

So final changes would be something like this:

package.json:

{
  "name": "app",
  "version": "0.0.0",
  "scripts": {
    "install": "node install-assets.js"
  }
  // ...
}

And in your install-assets.js file you can write codes to copy your files:

var ncp = require('ncp').ncp; // ~ npm i ncp

ncp('sourcePath', 'destPath', function (err) {
 if (err) {
   return console.error(err);
 }
 console.log('done!');
});
Mohi
  • 1,776
  • 1
  • 26
  • 39