By default ember-cli seems to be set up not to compile css files into one (as it does with the JS files).
What is the best way to configure ember-cli to merge all files in app/styles
(and subdirectories) into one app.css
file (and then fingerprint etc)? Is this possible via the Brocfile or do I need to override EmberApp.styles()
?
Update: As far as I can see there are the following (not very elegant) options:
1) Using SASS and @import
the CSS files into app.scss individually. The downside of this is that I need to use an extra plugin (SASS) and that SASS does not seem to allow for globbing patterns in @import
(e.g. @import('**/*.scss')
), which makes this solution cumbersome for big projects.
2) Overriding EmberApp.styles()
such that it does not copy the CSS files (this is currently being done by a wrapper around broccoli-static-compiler
) and configuring Broccoli such that it concatenates the css files into app.css
. This solution seems a bit hacky though and there is a risk of incompatibility with newer versions of ember-cli.
3) Workaround: Use broccoli-funnel
and broccoli-concat
to do the concatenation yourself.
In Brocfile.js:
var appTree = app.toTree()
var concatenated = concat(appTree, {
inputFiles: [
'**/*.css'
],
outputFile: '/assets/app.css',
});
module.exports = mergeTrees([appTree, concatenated], { overwrite: true });
This will create a new app.css
with all our concatenated CSS in /assets/app.css
.However, this file not fingerprinted. Our assets directory now looks something like this:
/assets/app.css
/assets/app-<fingerprint>.css
So a - admittedly hacky - second step is to 1) get the filename of the fingerprinted app-<fingerprint>.css
, 2) delete app-<fingerprint>.css
and 3) rename app.css to app-<fingerprint>.css
. This last step can be automated using Grunt or gulp.