Skip to content

Commit 2d63163

Browse files
committed
ensure import pattern
1 parent b2c1071 commit 2d63163

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

docs/project/external-modules.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,19 @@ This pattern is commonly used:
129129

130130
Similar to the lazy loading use case certain module loaders (commonjs/node and amd/requirejs) don't work well with circular dependencies. In such cases it is useful to have *lazy loading* code in one direction and loading the modules upfront in the other direction.
131131

132+
### Use case: Ensure Import
133+
134+
Sometimes you want to load a file just for the side effect (e.g the module might register itself with some library like CodeMirror providing commands etc.). However if you just do a `import/require` the transpiled JavaScript will not contain a dependency on the module and your module loader (e.g. webpack) might completely ignore the import. In such cases you can use a `ensureImport` variable to ensure that the compiled JavaScript takes a dependency on the module e.g.:
135+
136+
```ts
137+
import foo = require('./foo');
138+
import bar = require('./bar');
139+
import bas = require('./bas');
140+
const ensureImport: any =
141+
foo
142+
|| bar
143+
|| bas;
144+
```
145+
146+
132147
[](// TODO: es6 modules)

0 commit comments

Comments
 (0)