angularng-packagr

Use JS script file in angular library


I am trying to create an angular library in which one of the service has to make use of web-sdk.js file by importing it. Everything is working perfectly fine when I create that service inside of the application itself rather than a library, but there are some reason because of which I would rather have this service inside of a library.

Import statement that works in application but not in the library.

import sdk from '../../assets/web-sdk.js';

In the angular library I also tried entering a full path to the js file, but the I just get an error default' is not exported by...


Solution

  • I was able to solve it by creating a folder with the JS file and .d.ts file and adding this folder to the package.json dependency list - "sdk": "file:./external/sdk".

    After running yarn install I was able to make use of the JS lib by importing it - import sdk from 'sdk';