Verified Commit 79278bc1 authored by Eliot Berriot's avatar Eliot Berriot

Merge branch 'release/0.4'

parents 8a63313b 73e5f505
Pipeline #3388 failed with stages
in 3 minutes and 24 seconds
raw.json
data.json
src/assets/data.*
src/assets/data/data.*
.DS_Store
node_modules/
dist/
......
var fs = require('fs')
var UglifyJS = require('uglify-es')
module.exports = function(filePath) {
var code = fs.readFileSync(filePath, 'utf-8')
var result = UglifyJS.minify(code)
if (result.error) return ''
return result.code
}
// This service worker file is effectively a 'no-op' that will reset any
// previous service worker registered for the same host:port combination.
// In the production build, this file is replaced with an actual service worker
// file that will precache your site's local assets.
// See https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432
self.addEventListener('install', () => self.skipWaiting());
self.addEventListener('activate', () => {
self.clients.matchAll({ type: 'window' }).then(windowClients => {
for (let windowClient of windowClients) {
// Force open pages to refresh, so that they have a chance to load the
// fresh navigation response from the local dev server.
windowClient.navigate(windowClient.url);
}
});
});
(function() {
'use strict';
// Check to make sure service workers are supported in the current browser,
// and that the current page is accessed from a secure origin. Using a
// service worker from an insecure origin will trigger JS console errors.
const isLocalhost = Boolean(window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
window.addEventListener('load', function() {
if ('serviceWorker' in navigator &&
(window.location.protocol === 'https:' || isLocalhost)) {
navigator.serviceWorker.register('service-worker.js')
.then(function(registration) {
// updatefound is fired if service-worker.js changes.
registration.onupdatefound = function() {
// updatefound is also fired the very first time the SW is installed,
// and there's no need to prompt for a reload at that point.
// So check here to see if the page is already controlled,
// i.e. whether there's an existing service worker.
if (navigator.serviceWorker.controller) {
// The updatefound event implies that registration.installing is set
const installingWorker = registration.installing;
installingWorker.onstatechange = function() {
switch (installingWorker.state) {
case 'installed':
// At this point, the old content will have been purged and the
// fresh content will have been added to the cache.
// It's the perfect time to display a "New content is
// available; please refresh." message in the page's interface.
break;
case 'redundant':
throw new Error('The installing ' +
'service worker became redundant.');
default:
// Ignore
}
};
}
};
}).catch(function(e) {
console.error('Error during service worker registration:', e);
});
}
});
})();
......@@ -6,6 +6,7 @@ const merge = require('webpack-merge')
const baseWebpackConfig = require('./webpack.base.conf')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const loadMinified = require('./load-minified')
// add hot-reload related code to entry chunks
Object.keys(baseWebpackConfig.entry).forEach(function (name) {
......@@ -29,7 +30,9 @@ module.exports = merge(baseWebpackConfig, {
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true
inject: true,
serviceWorkerLoader: `<script>${fs.readFileSync(path.join(__dirname,
'./service-worker-dev.js'), 'utf-8')}</script>`
}),
new FriendlyErrorsPlugin()
]
......
......@@ -9,6 +9,8 @@ const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin')
const loadMinified = require('./load-minified')
const env = process.env.NODE_ENV === 'testing'
? require('../config/test.env')
......@@ -68,7 +70,9 @@ const webpackConfig = merge(baseWebpackConfig, {
// https://github.com/kangax/html-minifier#options-quick-reference
},
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency'
chunksSortMode: 'dependency',
serviceWorkerLoader: `<script>${loadMinified(path.join(__dirname,
'./service-worker-prod.js'))}</script>`
}),
// keep module.id stable when vender modules does not change
new webpack.HashedModuleIdsPlugin(),
......@@ -99,7 +103,24 @@ const webpackConfig = merge(baseWebpackConfig, {
to: config.build.assetsSubDirectory,
ignore: ['.*']
}
])
]),
new SWPrecacheWebpackPlugin({
cacheId: 'scp-browser',
filename: 'service-worker.js',
staticFileGlobs: ['dist/**/*.{js,html,css,woff2,woff,ttf,png,jpg}'],
minify: true,
stripPrefix: 'dist/',
runtimeCaching: [
{
urlPattern: /^http:\/\/scp-wiki\.wdfiles\.com\//,
handler: 'cacheFirst'
},
{
urlPattern: /\/static\/data\//,
handler: 'cacheFirst'
}
]
})
]
})
......
......@@ -5,6 +5,7 @@
<title>SCP Browser</title>
</head>
<body>
<%= htmlWebpackPlugin.options.serviceWorkerLoader %>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
......
This diff is collapsed.
var fs = require('fs')
var LZString = require ('lz-string')
var _in = 'data.json'
var _out = 'src/assets/data.lzs'
var _out = 'src/assets/data/data.lzs'
console.log('Compressing data...')
......
......@@ -160,19 +160,7 @@ export default {
}
},
updateQs: function () {
let query = {}
this.scpData.filters.forEach(f => {
let q = f.toQs(f.value)
if (q.length > 0) {
query[f.id] = q
}
})
if (this.scpData.sortAscending) {
query.sort = this.scpData.sortField
} else {
query.sort = '-' + this.scpData.sortField
}
query.page = this.scpData.page
let query = this.scpData.toQs()
this.$router.push({query})
},
selectPage: function (page, scroll) {
......
......@@ -197,7 +197,7 @@ var scpData = {
this.loading = false
return callback()
}
let url = require('./assets/data.lzs')
let url = require('./assets/data/data.lzs')
console.log('fetching data (this may take some time)...')
this.loading = true
$.ajax({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment