Skip to content

docs: add global lib usage instructions #6294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/documentation/stories/global-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,23 @@ You can also rename the output and lazy load it by using the object format:
{ "input": "pre-rename-script.js", "output": "renamed-script" },
],
```

## Using global libraries inside your app

Once you import a library via the scripts array, you should **not** import it via a import statement
in your TypeScript code (e.g. `import * as $ from 'jquery';`).
If you do that, you'll end up with two different copies of the library: one imported as a
global library, and one imported as a module.

This is especially bad for libraries with plugins, like JQuery, because each copy will have
different plugins.

Instead, download typings for your library (`npm install @types/jquery`) which will give you
access to the global variables exposed by that library.

If the global library you need to use does not have global typings, you can also declare them
manually in `src/typings.d.ts` as `any`:

```
declare var libraryName: any;
```