-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
310 additions
and
20 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// https://webpack.github.io/docs/loaders.html#writing-a-loader | ||
// http://stackoverflow.com/questions/35479987/query-not-found-for-webpack-custom-loader | ||
|
||
// don't change to ES6's arrow function because of 'this' context | ||
module.exports = function (source) { | ||
let rtn = source; | ||
this.cacheable(); | ||
// console.log('// ================================'); | ||
// console.log(this._compilation); | ||
// console.log(this); | ||
if (this.query.indexOf('name=service-worker') > -1) { | ||
rtn += `\n// ${Date.now()}`; // to change the hash value of service-worker.js on every build | ||
} else { // index.html | ||
if (this.options.metadata.github) { | ||
rtn = rtn.replace(/\/asset\//g, '/narr/asset/'); | ||
} | ||
} | ||
// console.log(rtn); | ||
return rtn; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// relative to output path | ||
|
||
module.exports = { | ||
include: { | ||
'/': true, | ||
}, | ||
exclude: { | ||
'asset/img/ic/ic.favicon.ico': true, | ||
'manifest.json': true, | ||
'service-worker.js': true, | ||
'js/main.bundle.js.map': true, | ||
'css/main.bundle.css.map': true, | ||
'js/polyfills.bundle.js.map': true, | ||
'js/vendor.bundle.js.map': true, | ||
'css/vendor.bundle.css.map': true | ||
} | ||
}; | ||
|
||
// const target = { | ||
// '/': true, | ||
// '/index.html': true, | ||
|
||
// '/css/vendor.bundle.css': true, | ||
// '/css/main.bundle.css': true, | ||
|
||
// '/js/polyfills.bundle.js': true, | ||
// '/js/vendor.bundle.js': true, | ||
|
||
// '/asset/img/bg.jpg': true, | ||
// '/asset/font/fontawesome-webfont.woff2': true, | ||
|
||
// '/asset/img/ic/angular.png': true, | ||
|
||
// '/asset/img/ic/ics-skill-language.png': true, | ||
// '/asset/img/ic/ics-skill-framework&library.png': true, | ||
// '/asset/img/ic/ics-skill-etc.png': true, | ||
|
||
// '/asset/img/ic/ic.narr.128x128.png': true, | ||
// '/asset/img/ic/ic.narr.144x144.png': true, | ||
// '/asset/img/ic/ic.narr.152x152.png': true, | ||
// '/asset/img/ic/ic.narr.192x192.png': true, | ||
// '/asset/img/ic/ic.narr.256x256.png': true, | ||
|
||
// '/asset/img/event.github.jpg': true, | ||
// '/asset/img/event.innorix.jpg': true, | ||
// '/asset/img/event.usoftation.jpg': true, | ||
// '/asset/img/event.cps-telecom.jpg': true | ||
// }; |
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
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"background_color": "#2080a9", | ||
"display": "standalone", | ||
"icons": [ | ||
{ | ||
"src": "/asset/img/ic/ic.narr.128x128.png", | ||
"sizes": "128x128", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "/asset/img/ic/ic.narr.144x144.png", | ||
"sizes": "144x144", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "/asset/img/ic/ic.narr.152x152.png", | ||
"sizes": "152x152", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "/asset/img/ic/ic.narr.192x192.png", | ||
"sizes": "192x192", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "/asset/img/ic/ic.narr.256x256.png", | ||
"sizes": "256x256", | ||
"type": "image/png" | ||
} | ||
], | ||
"name": "Narr's Website", | ||
"short_name": "Narr", | ||
"start_url": "/index.html", | ||
"theme_color": "#1667b7" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// https://developers.google.com/web/fundamentals/getting-started/your-first-progressive-web-app/?hl=en | ||
// https://github.com/GoogleChrome/sw-precache | ||
// https://github.com/GoogleChrome/samples | ||
// http://stackoverflow.com/questions/34160509/options-for-testing-service-workers-via-http | ||
|
||
// cacheName should be replaced with new one to get new files | ||
const cacheName = 'narr?' + Date.now(); | ||
const filesToCache = 'SW_CACHE_TARGET'; // 'SW_CACHE_TARGET' will be replace by webpack | ||
|
||
// install | ||
self.addEventListener('install', e => { | ||
console.log('[ServiceWorker] ' + new Date().toString()); | ||
|
||
e.waitUntil(self.caches.open(cacheName).then(cache => { | ||
console.log('[ServiceWorker] Caching app'); | ||
return cache.addAll(filesToCache); | ||
})); | ||
|
||
if (typeof self.skipWaiting === 'function') { | ||
console.log('self.skipWaiting() is supported.'); | ||
e.waitUntil(self.skipWaiting()); | ||
} else { | ||
console.log('self.skipWaiting() is not supported.'); | ||
} | ||
}); | ||
|
||
// activate | ||
self.addEventListener('activate', e => { | ||
console.log('[ServiceWorker] Activate'); | ||
|
||
e.waitUntil(self.caches.keys().then(keyList => { | ||
return Promise.all(keyList.map(key => { | ||
if (key !== cacheName) { | ||
console.log('[ServiceWorker] Removing old cache', key); | ||
return self.caches.delete(key); | ||
} | ||
})); | ||
})); | ||
|
||
if (self.clients && typeof self.clients.claim === 'function') { | ||
console.log('self.clients.claim() is supported.'); | ||
e.waitUntil(self.clients.claim()); | ||
} else { | ||
console.log('self.clients.claim() is not supported.'); | ||
} | ||
}); | ||
|
||
// fetch | ||
self.addEventListener('fetch', e => { | ||
console.log('[ServiceWorker] Fetch', e.request.url); | ||
|
||
const mainBundleUrl = '/js/main.bundle.js'; | ||
if (e.request.url.indexOf(mainBundleUrl) > -1) { | ||
e.respondWith(self.fetch(e.request) // to get the latest service-worker.js | ||
.then(response => { | ||
return self.caches.open(cacheName).then(cache => { | ||
cache.put(e.request.url, response.clone()); | ||
console.log('[ServiceWorker] Fetched&Cached Data'); | ||
return response; | ||
}); | ||
}) | ||
.catch(err => { | ||
console.log('fetch error..!! and retrieve from cache..!!'); | ||
// console.log(err); | ||
return self.caches.match(e.request).then(response => { | ||
return response || self.fetch(e.request); // if no cache, try fetching one more | ||
}); | ||
}) | ||
); | ||
} else { | ||
e.respondWith(self.caches.match(e.request).then(response => { | ||
return response || self.fetch(e.request); | ||
})); | ||
} | ||
}); |
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