Include Files at the Root of Your Ember Project
I recently had a need to include two files at the root of my ember project - a service worker and a manifest file.
I sought fine-grained control over my service worker, a la not using the fabulous ember-service-worker plugin.
To accomplish this, I made a few small changes to my ember-cli-build file.
The first two changes involve:
- defining the two files to be placed into the root directory in a constant at the top of the exports function
- adding two dependencies to the top of the ember-cli-build file
//ember-cli-build.js
module.exports = function(defaults) {
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
const mergeTrees = require('broccoli-merge-trees'); //add this dependency
const Funnel = require('broccoli-funnel'); //add this dependency
const STATIC_FILES = ['manifest.json', 'service-worker.js'] //define your files here
Then, create a tree using the STATIC_FILES constant defined above, and in that tree, instruct broccoli to put the tree's files in the root directory:
var staticTree = new Funnel("./public/assets", {
include: STATIC_FILES,
destDir: '.'
})
On the next build, the service worker and manifest files should be in the root of the dist/ folder.
The service worker will be fingerprinted and minified. In most situations this is great, but not this one.
To prevent the service worker from being fingerprinted and minified, we can instruct broccoli to exclude it from those processes: