Skip to content
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

Add section on importing a module for side affects only to the README.md #594

Merged
merged 5 commits into from
Nov 1, 2023
Merged
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions packages/ember-auto-import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,23 @@ let app = new EmberApp(defaults, {
});
```

### I want to import a module for side affects only.
mansona marked this conversation as resolved.
Show resolved Hide resolved
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.
mansona marked this conversation as resolved.
Show resolved Hide resolved

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#:~:text=Import%20a%20module%20for%20its%20side%20effects%20only).<br>
mansona marked this conversation as resolved.
Show resolved Hide resolved
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.<br>
This can be imported like:
mansona marked this conversation as resolved.
Show resolved Hide resolved

```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