Created
February 21, 2017 18:07
-
-
Save natecox/b19c4e08408a5bf0d4cf4d74f1902260 to your computer and use it in GitHub Desktop.
Phoenix-Framework Brunch config for sw-precache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let glob = require('glob') | |
exports.config = { | |
// See http://brunch.io/#documentation for docs. | |
files: { | |
javascripts: { | |
joinTo: "js/app.js" | |
}, | |
stylesheets: { | |
joinTo: "css/app.css", | |
order: { | |
after: ["web/static/css/app.css"] // concat app.css last | |
} | |
}, | |
templates: { | |
joinTo: "js/app.js" | |
} | |
}, | |
conventions: { | |
assets: /^(web\/static\/assets)/ | |
}, | |
paths: { | |
watched: [ | |
"web/static", | |
"test/static" | |
], | |
// Where to compile files to | |
public: "priv/static" | |
}, | |
// Configure your plugins | |
plugins: { | |
babel: { | |
// Do not use ES6 compiler in vendor code | |
ignore: [/web\/static\/vendor/] | |
}, | |
swPrecache: { | |
swFileName: 'service-worker.js', | |
directoryIndex: '/', | |
options: { | |
stripPrefix: 'priv/static/', | |
staticFileGlobs: ['priv/static/**/*.*'], | |
dynamicUrlToDependencies: { | |
'/': [ | |
...glob.sync('priv/static/**/*.js'), | |
...glob.sync('priv/static/**/*.css'), | |
...glob.sync('web/templates/**/*.eex'), | |
] | |
} | |
} | |
} | |
}, | |
modules: { | |
autoRequire: { | |
"js/app.js": ["web/static/js/app"] | |
} | |
}, | |
npm: { | |
enabled: true | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a bare-bones config for sw-precache using brunch and focused on the default Phoenix Framework setup.
Note that a single URL has been defined under
dynamicUrlToDependencies
, which points to the project root. In this config, any change to any.eex
,.js
, or.css
in the project will cause that URL to be re-cached. In practice, you will want to update this to be much more restrictive.