2

I am attempting to use a 3rd party library in my Angular 5 app by configuring global scripts. This question outlines what I am trying to do although I think this might be at Angular 4: Loading third party library with Angular-cli

The library I am trying to use is shpjs, so my scripts property is:

  "scripts": [
    "../node_modules/shpjs/dist/shp.js"
  ],

The app builds fine, but my library is not present in my index.html. According to the docs:

These will be loaded exactly as if you had added them in a tag inside index.html

Is there another step that I am missing?

*Update: *
I had other issues which I finally got sorted out. To sum up, my script configuration was correct but my import statement in my component was not and I was conflating one issue with another.

In my component.ts, I added import * as shp from 'shpjs';

And then my test function on my component worked just fine:

  openAsGeoJson(url: string) {
    url = 'http://calvinmetcalf.github.io/shapefile-js/files/TM_WORLD_BORDERS_SIMPL-0.3.zip';


    shp(url).then(function (data) {
      if (data) {
        console.log('shapefile data received');
        console.log(data.length);
        console.log(data);
      }

    });
  }

My Environment:

Angular CLI: 1.6.3
Node: 7.10.1
OS: win32 x64
Angular: 5.2.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.6.3
2
  • 1
    "as if you had" doesn't mean that's how it's actually done. They're included in the bundled JavaScript. Commented May 10, 2018 at 19:35
  • ok...that makes sense. and yes, it's in there. Commented May 10, 2018 at 19:41

1 Answer 1

4

It doesnt get added to the index.html as is.

<script src="../node_modules/shpjs/dist/shp.js" />

It gets added in scripts.bundle.js

There will a script tag in index.html as below,

<script type="text/javascript" src="scripts.bundle.js"></script>

The shp.js file will be part of scripts.bundle.js, Open this file and you can find shp.js contents.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.