Skip to content

How do I use a 3rd party lib required by a script tag in the html file? #1171

Closed
abhiit89/angular-cli
#13

Description

@NullVoxPopuli

I've given up with imports/requires, so I am trying the script-tag way.

in src/index.html:

  {{#unless environment.production}}
  <!-- These two files (used for testing) cannot be included the 'normal' way,
  because angular-cli's build tools don't resolve dependencies of 3rd party libs. -->
  <script src="/dist/vendor/sinon/pkg/sinon.js" type="text/javascript"></script>
  <script src="/dist/vendor/axios/dist/axios.js" type="text/javascript"></script>
  {{/unless}}
</head>

and in angular-cli-build.js:

    vendorNpmFiles: [
     ...
      'sinon/**/*.js',
    ],

and then in my test:

declare var sinon:any;
...
  beforeEach(() => sandbox = sinon.sandbox.create());

I get the error:

     ReferenceError: sinon is not defined

$ ng --version
angular-cli: 1.0.0-beta.6
node: 5.10.1
os: linux x64

how do I use the library?

after running ng test, there are 0 console errors in the opened chrome window. The errors are only in the terminal.

Activity

  1. RicardoVaranda commented on Jun 23, 2016

    @RicardoVaranda
    Contributor

    The way you are calling the scripts is wrong:
    <script src="/dist/vendor/axios/dist/axios.js" type="text/javascript"></script>

    Should be:
    <script src="vendor/axios/dist/axios.js" type="text/javascript"></script>

    If you open the Developer tools in Google Chrome go to Console unselect Hide network messages and you should see the 404

    Hope you see the difference :)

  2. NullVoxPopuli commented on Jun 23, 2016

    @NullVoxPopuli
    Author

    I changed the script tags in my index.html file to:

      <script src="vendor/sinon/pkg/sinon.js" type="text/javascript"></script>
      <script src="vendor/axios/dist/axios.js" type="text/javascript"></script>
    

    my chrome has never given me 404s with this issue:
    image

    image

    In the network pane, I don't even see a call to sinon.js

    image

  3. NullVoxPopuli commented on Jun 23, 2016

    @NullVoxPopuli
    Author

    the same thing happens with jQuery, so it's non sinon specific

  4. filipesilva commented on Jul 28, 2016

    @filipesilva
    Contributor

    Closed as issue was made obsolete by #1455. You shouldn't have the issue that originally led to this approach, as webpack handles the dependencies of dependencies as you would expect it to.

  5. angular-automatic-lock-bot commented on Sep 6, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  6. locked and limited conversation to collaborators on Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions