Skip to content

Commit cf2352f

Browse files
filipesilvasumitarora
authored andcommitted
docs: add global lib usage instructions (#6294)
See #6033 for context.
1 parent 517be88 commit cf2352f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/documentation/stories/global-scripts.md

+20
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,23 @@ You can also rename the output and lazy load it by using the object format:
2121
{ "input": "pre-rename-script.js", "output": "renamed-script" },
2222
],
2323
```
24+
25+
## Using global libraries inside your app
26+
27+
Once you import a library via the scripts array, you should **not** import it via a import statement
28+
in your TypeScript code (e.g. `import * as $ from 'jquery';`).
29+
If you do that, you'll end up with two different copies of the library: one imported as a
30+
global library, and one imported as a module.
31+
32+
This is especially bad for libraries with plugins, like JQuery, because each copy will have
33+
different plugins.
34+
35+
Instead, download typings for your library (`npm install @types/jquery`) which will give you
36+
access to the global variables exposed by that library.
37+
38+
If the global library you need to use does not have global typings, you can also declare them
39+
manually in `src/typings.d.ts` as `any`:
40+
41+
```
42+
declare var libraryName: any;
43+
```

0 commit comments

Comments
 (0)