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

Document altering entry point (allowing ember addon and "normal" package usage). #116

Open
rwjblue opened this issue Jun 5, 2019 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@rwjblue
Copy link
Contributor

rwjblue commented Jun 5, 2019

In ember-cli (for a very very long time) it has been possible to have ember-cli use a different main entry point for the addon than what a normal require('my-package-name') would return.

The way to do this is to add an "ember-addon": { "main": "some-other-file.js" } to your package.json. Normal require invocation will look at the main entry point, and ember-cli will look at some-other-file.js.

One nice benefit of this is that if you make main be addon/index.js and ember-addon.main be index.js, "normal" node_module resolution rules apply for things in addon/index.js. This means that things like eslint-plugin-import and TypeScript can actual see and validate an import from the addon name (though not with nested paths).

For example, typescript (and eslint-plugin-import) would see that this is valid:

import Component from 'sparkles-component';

export default class extends Component {}

See rwjblue/sparkles-component#23 as an example.

@rwjblue rwjblue added the help wanted Extra attention is needed label Jun 5, 2019
@xg-wang
Copy link

xg-wang commented Dec 12, 2019

I think this should be a RFC and built into default addon blueprint, rather than teaching addon authors.
^^ For the making typescript happy part, this needs to be documented

Copy link
Contributor Author

rwjblue commented Dec 12, 2019

Sure, seems totally fine to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants