Skip to content

Commit

Permalink
Update README.md (#594)
Browse files Browse the repository at this point in the history
Add a section to the readme on importing a module for side affects only


---------

Co-authored-by: Chris Manson <mansona@users.noreply.github.com>
Co-authored-by: Andrey Mikhaylov (lolmaus) <lolmaus@gmail.com>
  • Loading branch information
3 people committed Nov 1, 2023
1 parent dfe85ed commit 22fa232
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/ember-auto-import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,24 @@ let app = new EmberApp(defaults, {
});
```

### I want to import a module for side effects only.

Some modules, often times polyfills, don't provide values meant for direct import. Instead, the module is meant to provide certain side affects, such as mutating global variables.
To import a module for side affects only, you can simply [import the module directly](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#import_a_module_for_its_side_effects_only).<br>
Any side affects the module provides will take affect.
Example: the `eventsource` package provides a ready to use [eventsource-polyfill.js](https://github.com/EventSource/eventsource/blob/master/example/eventsource-polyfill.js) module.
This can be imported like:
```js
// In any js file, likely the file you need to access the polyfill, purely for organization.
// Importing the polyfill adds a new global object EventSourcePolyfill.
import 'eventsource/example/eventsource-polyfill.js';
```
## Debugging Tips
Set the environment variable `DEBUG="ember-auto-import:*"` to see debug logging during the build.
Expand Down

0 comments on commit 22fa232

Please sign in to comment.