Comments (5)
Any update on this?
from sw-precache.
With the caveat that I have very little experience working with Grunt
: the output shows that the sw-precache.write()
call is running, but the list of files to precache, determined by staticFileGlobs
, is coming back empty.
That makes me think that the rootDir
value you're using isn't appropriate, perhaps because it's a relative path that assumes a different current working directory. I also notice that there's a <%= yeoman.dist %>
variable declared in your build script, and perhaps that's a better value to use.
To debug this, just try executing a similar glob.sync(rootDir + '/**/*.{html,css,js,jpg,png}')
from within your task, and see what the output is. I'm going to assume it's not finding any files, either.
from sw-precache.
Hi @jeffposnick you were absolutely right.
After i change the rootdir from a relative path rootDir: 'dist'
to the yeoman path rootDir: '<%= yeoman.dist %>'
, everything worked seamlessly. Thank you!
Closing this issue as my problem is solved!
Thanks for the great tool @jeffposnick !
from sw-precache.
Hello @jaspersorrio @jeffposnick I am facing the same problem but i am not able to get the solution, please help
Here is my grunt file
'use strict';
module.exports = function(grunt) {
var swPrecache = require('./node_modules/sw-precache/lib/sw-precache.js'),
path = require('path');
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
// Project settings
mifosx: {
// configurable paths
app: require('./bower.json').appPath || 'app',
dist: 'dist',
target: 'community-app',
test: 'test',
almond: 'app/bower_components/almond'
},
watch: {
js: {
files: ['<%= mifosx.app %>/scripts/**/*.js'],
options: {
livereload: true
}
},
scss: {
files: ['<%= mifosx.app %>/styles-dev/**/*.scss'],
tasks: ['compass:dev']
},
gruntfile: {
files: ['Gruntfile.js']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= mifosx.app %>/**/*.html',
'<%= mifosx.app %>/{,*/}*.json',
'<%= mifosx.app %>/**/*.js',
'<%= mifosx.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
// ignore directories to reduce CPU usage by watch/node process
'!<%= mifosx.app %>/bower_components/**',
// also ignore all css file changes
'<%= mifosx.app %>/styles/*.css'
]
}
},
// The actual grunt server settings
connect: {
options: {
port: 9002,
hostname: 'localhost',
livereload: 35729,
open:'http://<%= connect.options.hostname %>:<%= connect.options.port %>?baseApiUrl=https://demo.openmf.org'
},
livereload: {
options: {
base: [
'.tmp',
'<%= mifosx.app %>'
]
}
}
},
// w3c html validation
validation: {
options: {
reset: true,
relaxerror: ['no document type declaration; will parse without validation', 'document type does not allow element \\"[A-Z]+\\" here']
},
files: {
src: [
'<%= mifosx.app %>/views/{,*/}*.html', // Validating templates may not be of much use.
'<%= mifosx.app %>/index.html'
]
}
},
// Make sure code styles are up to par and there are no obvious mistakes
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish'),
reporterOutput:'jshint-log.xml',
force: true
},
all: ['Gruntfile.js', '<%= mifosx.app %>/scripts/**/*.js']
},
karma: {
unit: {
configFile: 'karma.conf.js'
}
},
//uglify the js files
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
prod: {
files: [{
'<%= mifosx.dist %>/<%=mifosx.target%>/bower_components/angular-mocks/angular-mocks.min.js'
:['<%= mifosx.app %>/bower_components/angular-mocks/angular-mocks.js'],
'<%= mifosx.dist %>/<%=mifosx.target%>/bower_components/angular-webstorage/angular-webstorage.min.js'
:['<%= mifosx.app %>/bower_components/angular-webstorage/angular-webstorage.js'],
'<%= mifosx.dist %>/<%=mifosx.target%>/bower_components/q/q.min.js'
:['<%= mifosx.app %>/bower_components/q/q.js'],
//'<%= mifosx.dist %>/<%=mifosx.target%>/bower_components/datatables/media/js/jquery.dataTables.min.js'
//:['<%= mifosx.app %>/bower_components/datatables/media/js/jquery.dataTables.js'],
//'<%= mifosx.dist %>/<%=mifosx.target%>/bower_components/require-css/css.min.js'
//:['<%= mifosx.app %>/bower_components/require-css/css.js'],
//'<%= mifosx.dist %>/<%=mifosx.target%>/bower_components/requirejs/requirejs.min.js'
//:['<%= mifosx.app %>/bower_components/requirejs/require.js'],
'<%= mifosx.dist %>/<%=mifosx.target%>/bower_components/underscore/underscore.min.js'
:['<%= mifosx.app %>/bower_components/underscore/underscore.js'],
'<%= mifosx.dist %>/<%=mifosx.target%>/bower_components/angular-utils-pagination/dirPagination.min.js'
:['<%= mifosx.app %>/bower_components/angular-utils-pagination/dirPagination.js']
}]
}
},
// Empties folders to start fresh
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'<%= mifosx.dist %>/*',
'!<%= mifosx.dist %>/.git*'
]
}]
},
//trying to remove unused css files
/*css: ['<%= mifosx.dist %>/<%=mifosx.target%>/styles/*.css', '!<%= mifosx.dist %>/<%=mifosx.target%>/styles/*.min.css'],*/
server: '.tmp'
},
// Copies remaining files to places other tasks can use
copy: {
prod: {
files: [{
expand: true,
dot: true,
cwd: '<%= mifosx.app %>',
dest: '<%= mifosx.dist %>/<%=mifosx.target%>',
src: [
'*.{ico,png,txt}',
'.htaccess',
'images/{,*/}*.{webp}',
'fonts/*',
'images/*',
'scripts/*.js',
'scripts/config/*.json',
'scripts/services/*.js',
'scripts/modules/*.js',
'!scripts/routes.js',
'!scripts/initialTasks.js',
'!scripts/webstorage-configuration.js',
'!scripts/mifosXComponents.js',
'!scripts/mifosXComponents-build.js',
'!scripts/loader.js',
'!scripts/loader-build.js',
'styles/**.css',
'!scripts/mifosXStyles.js',
'!scripts/mifosXStyles-build.js',
'global-translations/**',
'*.html',
'release.json',
'views/**',
'angular/**'
]
},
{
expand: true,
dot: true,
cwd: '<%= mifosx.test %>',
dest: '<%= mifosx.dist %>/<%=mifosx.target%>/test',
src: [
'**/**'
]
},
{
'<%= mifosx.dist %>/<%=mifosx.target%>/scripts/mifosXComponents.js':['<%= mifosx.app %>/scripts/mifosXComponents-build.js'],
'<%= mifosx.dist %>/<%=mifosx.target%>/scripts/loader.js':['<%= mifosx.app %>/scripts/loader-build.js'],
'<%=mifosx.dist %>/<%=mifosx.target%>/scripts/mifosXStyles.js':['<%=mifosx.app%>/scripts/mifosXStyles-build.js']
//'<%= mifosx.dist %>/<%=mifosx.target%>':['<%= mifosx.test %>/**']
},
{
expand: true,
dot: true,
cwd: '<%= mifosx.app %>/bower_components',
dest: '<%= mifosx.dist %>/<%=mifosx.target%>/bower_components',
src: [
'**/*min.js', 'ckeditor/**', 'chosen/**', 'require-css/*.js', 'require-less/*.js',
'!jasmine/**', '!requirejs/**/**', 'requirejs/require.js', '!underscore/**',
'angular-utils-pagination/dirPagination.tpl.html'
]
}
]
},
dev: {
files: [{
expand: true,
dot: true,
cwd: '<%= mifosx.app %>',
dest: '<%= mifosx.dist %>/<%=mifosx.target%>',
src: [
'*.{ico,png,txt}',
'.htaccess',
'images/{,*/}*.{webp}',
'fonts/*',
'scripts/**/*.js',
'global-translations/**',
'styles/**',
'*.html',
'views/**',
'images/**',
'bower_components/**'
]
},
{
expand: true,
dot: true,
cwd: '<%= mifosx.test %>',
dest: '<%= mifosx.dist %>/<%=mifosx.target%>/test',
src: [
'**/**'
]
}]
},
// this won't be necessary after fixing dependencies
server: {
expand: true,
dot: true,
cwd: '<%= mifosx.test %>',
dest: '.tmp/test',
src: '**/**'
}
},
//hashing css & js
hashres: {
options: {
encoding: 'utf8',
fileNameFormat: '${name}.${hash}.${ext}',
renameFiles: true
},
css: {
options: {
},
dest: '<%= mifosx.dist %>/<%=mifosx.target%>/scripts/mifosXStyles.js',
src: ['<%= mifosx.dist %>/<%=mifosx.target%>/styles/*.css','!<%= mifosx.dist %>/<%=mifosx.target%>/styles/font-awesome.min.css']
},
js: {
options: {
},
dest: ['<%= mifosx.dist %>/<%=mifosx.target%>/scripts/mifosXComponents.js'],
src: [
'<%= mifosx.dist %>/<%=mifosx.target%>/scripts/directives/directives.js',
'<%= mifosx.dist %>/<%=mifosx.target%>/scripts/routes-initialTasks-webstorage-configuration.js',
'<%= mifosx.dist %>/<%=mifosx.target%>/scripts/controllers/controllers.js',
'<%= mifosx.dist %>/<%=mifosx.target%>/scripts/filters/filters.js',
'<%= mifosx.dist %>/<%=mifosx.target%>/scripts/models/models.js',
'<%= mifosx.dist %>/<%=mifosx.target%>/scripts/config/UIConfig.json'
]
},
ext : {
options: {},
dest: '<%= mifosx.dist %>/<%=mifosx.target%>/scripts/loader.js',
src: ['<%= mifosx.dist %>/<%=mifosx.target%>/scripts/mifosXComponents.js','<%= mifosx.dist %>/<%=mifosx.target%>/scripts/mifosXStyles.js']
},
loader : {
options: {},
src: '<%= mifosx.dist %>/<%=mifosx.target%>/scripts/loader.js',
dest: '<%= mifosx.dist %>/<%=mifosx.target%>/index.html'
}
},
// rename files
replace: {
text: {
src: ['<%= mifosx.dist %>/<%=mifosx.target%>/scripts/mifosXComponents*','<%= mifosx.dist %>/<%=mifosx.target%>/scripts/loader*'],
overwrite: true,
replacements: [{
from: '.js',
to: ''
}]
}
},
// concatinate JS files
/** FIXME: Address issues with this task**/
concat: {
options: {
separator: ';'
},
//
dist: {
files: {
'<%= mifosx.dist %>/<%=mifosx.target%>/scripts/controllers/controllers.js': ['<%= mifosx.app %>/scripts/controllers/**/*.js'],
'<%= mifosx.dist %>/<%=mifosx.target%>/scripts/directives/directives.js': ['<%= mifosx.app %>/scripts/directives/**/*.js'],
'<%= mifosx.dist %>/<%=mifosx.target%>/scripts/models/models.js': ['<%= mifosx.app %>/scripts/models/**/*.js'],
//'<%= mifosx.dist %>/<%=mifosx.target%>/scripts/services/services.js': ['<%= mifosx.app %>/scripts/services/**/*.js'],
'<%= mifosx.dist %>/<%=mifosx.target%>/scripts/filters/filters.js': ['<%= mifosx.app %>/scripts/filters/**/*.js'],
'<%= mifosx.dist %>/<%=mifosx.target%>/scripts/routes-initialTasks-webstorage-configuration.js':
['<%= mifosx.app %>/scripts/routes.js',
'<%= mifosx.app %>/scripts/initialTasks.js',
'<%= mifosx.app %>/scripts/webstorage-configuration.js']
}
}
//trying to concatenat css files
/*css: {
files: {
'<%= mifosx.dist %>/<%=mifosx.target%>/styles/mifosXstyle.css':
['<%= mifosx.app %>/styles/app.css',
'<%= mifosx.app %>/styles/bootstrap-ext.css',
'<%= mifosx.app %>/styles/bootswatch.css',
'<%= mifosx.app %>/styles/style.css'],
'<%= mifosx.dist %>/<%=mifosx.target%>/styles/vendorStyle.css':
['<%= mifosx.app %>/styles/bootstrap.min.css',
'<%= mifosx.app %>/styles/chosen.min.css',
'<%= mifosx.app %>/styles/font-awesome.min.css',
'<%= mifosx.app %>/styles/nv.d3.css',
'<%= mifosx.app %>/styles/ui-bootstrap-csp.css'],
}
}*/
},
//here is the task for the grunt-contrib-requirejs
requirejs: {
compile: {
options: {
name: '../bower_components/almond/almond',
baseUrl: './app',
mainConfigFile: '<%= mifosx.app %>/scripts/loader.js',
out: '<%= mifosx.dist %>/finaljs/app.js'
}
}
},
devcode: {
options: {
html: true, // html files parsing?
js: true, // javascript files parsing?
css: false, // css files parsing?
clean: true, // removes devcode comments even if code was not removed
block: {
open: 'devcode', // with this string we open a block of code
close: 'endcode' // with this string we close a block of code
},
dest: 'dist' // default destination which overwrittes environment variable
},
dist : { // settings for task used with 'devcode:dist'
options: {
source: 'dist/',
dest: 'dist/',
env: 'production'
}
}
},
//compass task to compile scss to css files
compass: { // Task
dist: { // Target
options: { // Target options
sassDir: 'app/styles-dev/main',
cssDir: 'app/styles/',
environment: 'production',
require: 'sass-css-importer'
}
},
dev: { // Another target
options: {
sassDir: 'app/styles-dev/main',
cssDir: 'app/styles/',
require: 'sass-css-importer'
}
}
},
swPrecache:{ //Task
dev:{ //Target
handleFetch: false,
rootDir : '<%= mifosx.app %>'
}
},
//cssmin task to concatenate and minified css file while running the grunt prod
/*cssmin: {
target: {
files: [{
expand: true,
dot: true,
cwd: '<%= mifosx.dist %>/<%=mifosx.target%>/styles/',
src: ['styles.css'],
dest: '<%= mifosx.dist %>/<%=mifosx.target%>/styles/',
ext: '.min.css'
}]
}
}*/
});
function writeServiceWorkerFile(rootDir, handleFetch, callback){
var config = {
cacheId : 'Mifos-app',
handleFetch : handleFetch,
logger : grunt.log.writeln,
staticFileGlobs: [rootDir + '/**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff,json}'],
stripPrefix : rootDir + '/',
verbose: true
};
swPrecache.write(path.join(rootDir,'service-worker.js'), config, callback);
}
// Run development server using grunt serve
grunt.registerTask('serve', ['clean:server', 'copy:server', 'connect:livereload', 'watch']);
// Validate JavaScript and HTML files
grunt.registerTask('validate', ['jshint:all', 'validation']);
// Default task(s).
grunt.registerTask('default', ['clean', 'jshint', 'copy:dev']);
grunt.registerTask('prod', ['clean:dist', 'clean:server', 'compass:dist', 'copy:prod', 'concat', 'uglify:prod', 'devcode:dist', 'hashres','replace', 'swPrecache']);
grunt.registerTask('dev', ['clean', 'compass:dev', 'copy:dev','swPrecache:dev']);
grunt.registerTask('test', ['karma']);
grunt.registerMultiTask('swPrecache', function(){
var done = this.async();
var rootDir = this.data.rootDir;
var handleFetch = this.data.handleFetch;
writeServiceWorkerFile(rootDir, handleFetch, function(error){
if( error){
grunt.fail.warn(error);
}
done();
});
});
};
from sw-precache.
I solved my problem my changing line :)
grunt.registerTask('serve', ['clean:server', 'copy:server', 'connect:livereload','swPrecache','watch']);
from sw-precache.
Related Issues (20)
- sw-precache don't work with css HOT 1
- Where is the precache option such as in the toolbox precache method
- This is my code and I its not working
- [Question] Production Cache Issue
- skipWaiting false and a refresh button HOT 2
- runtimeCaching with client side routing with javascript and html
- SW precaching static assets delaying onload? HOT 4
- service worker request many resources.And when user fetch something, this request is blocked
- Give more abstraction to the filesystem
- Cache Fetch fails on iOS HOT 1
- service worker CORS opaque response error HOT 2
- RuntimeCaching is not working when handleFetch is set to false.
- Serve cached resource and then update in background HOT 1
- sw-precache freezes on vueJS build HOT 1
- Generated service worker doesn't claimClient or skipWaiting on Chrome 71 incognito
- RuntimeCaching is not working with Protractor & Selenium automated test.
- workbox is not defined (window 10) HOT 1
- Vulnerability in lodash.template dependency HOT 1
- Extension only works once after installing or re-installing
- Failed to compile
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sw-precache.