I'm developing an ember addon which imports sass from it's dependencies. To use it I have the following in my addon -
# my-addon/package.json
...
"dependencies": {
"lib1": "^1.5.3",
"lib2": "1.2.3",
"ember-cli-sass": "^10.0.1",
"sass": "^1.23.3"
}
...
# my-addon/addon/styles/addon.scss
@import "lib1/assets/stylesheets/styles";
@import "lib2/assets/stylesheets/styles";
# my-addon/ember-cli-build.js
let app = new EmberAddon(defaults, {
// Add options here
sassOptions: {
includePaths: [
'node_modules'
]
}
});
This way, the dummy app at tests/dummy can resolve the imports. But when I use the addon in my host app, I get
Error: Can't find stylesheet to import.
╷
1 │ @import "lib1/assets/stylesheets/styles";
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I can modify my host app's ember-cli-build.js to
let app = new EmberAddon(defaults, {
// Add options here
sassOptions: {
includePaths: [
'node_modules/my-addon/node_modules'
]
}
});
and ideally it should work but sass runs out of memory because it tries to import everything in node_modules of my host app. How do I make this work for both the dummy app and the host app still be able to import namespaced lib scss?
Writing my addon I had the same problems!
Researching a lot and mixing the learnings, I came to the following resolution.
Describing scenario:
Writing an EmberJS Addon to provide material design components installing the library locally and only for components and behaviors that I want my addon, reuse and expose as custom ember components. Something like the adopted addon Ember paper.
Ember version and @material dependencies.
Notice that for this answer I only added @material/typography
For the first time, I fell into the same mistake -> Add
sassOptionsto ember-cli-build.jsincluding the wholenode_modulespath. But the comment that the addon-cli wrote in theember-cli-build` file made me realize that I was wrong.The Solution
To begin we should install some npm packages
resolve:
broccoli-funnel:
broccoli-merge-trees:
With this, you should be able to use the addon with its external sass files in the dummy app or in another application using the npm link or publishing the addon.
Notice that I preferred to force addon consumers to import the
@import 'my-addon-scss';. I had not test providing styles directly on the#my-addon/addon/styles/addon.scss.I believe this answer can start the discussion about creating ember add-ons.
I hope I receive answers to make my code better.
References