Version-handling

This commit is contained in:
Kasper Rynning-Tønnesen
2020-01-30 13:10:55 +01:00
parent 7a20115e28
commit e8a6284f02
6 changed files with 75 additions and 10 deletions

1
.gitignore vendored
View File

@@ -1,6 +1,7 @@
.DS_Store
public/index.html
public/sw/
# Logs
logs

View File

@@ -0,0 +1,49 @@
"use strict";
const webpack = require("webpack");
const helpers = require("./helpers");
const UglifyJSPlugin = require("uglifyjs-webpack-plugin");
const ServiceWorkerConfig = {
resolve: {
extensions: [".js", ".vue"]
},
entry: {
serviceWorker: [helpers.root("public", "service-worker")]
},
optimization: {
minimizer: []
},
module: {
rules: [
{
test: /\.js$/,
loader: "babel-loader",
include: [helpers.root("public", "service-worker")]
}
]
},
mode: "production",
output: {
path: helpers.root("public/sw"),
publicPath: "/",
filename: "[name].js"
//filename: "js/[name].bundle.js"
},
optimization: {
minimizer: [
new UglifyJSPlugin({
cache: true,
parallel: false,
sourceMap: false
})
]
},
plugins: [
new webpack.DefinePlugin({
__DATE__: new Date().getTime()
})
]
};
module.exports = ServiceWorkerConfig;

View File

@@ -1,6 +1,7 @@
"use strict";
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const path = require("path");
const webpack = require("webpack");
const merge = require("webpack-merge");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
@@ -19,7 +20,7 @@ const webpackConfig = merge(commonConfig(false), {
path: helpers.root("public/dist"),
publicPath: "/dist/",
filename: "js/[name].bundle.[hash:7].js"
//filename: 'js/[name].bundle.js'
//filename: "js/[name].bundle.js"
},
optimization: {
splitChunks: {
@@ -50,6 +51,7 @@ const webpackConfig = merge(commonConfig(false), {
new webpack.EnvironmentPlugin(environment),
new MiniCSSExtractPlugin({
filename: "css/[name].[hash:7].css"
//filename: "css/[name].css"
})
]
});

View File

@@ -1,9 +1,10 @@
var version = "v1.0";
var cacheName = "::vinlottis";
var CACHE_NAME = version + cacheName;
var CACHE_NAME_API = version + cacheName + "::api";
var version = "v1.0" + __DATE__;
var cacheName = "vinlottis";
var CACHE_NAME = cacheName;
var CACHE_NAME_API = cacheName + "::api";
var STATIC_CACHE_URLS = ["/"];
console.log("Nåværende versjon:", version);
self.addEventListener("activate", event => {
event.waitUntil(
caches
@@ -12,7 +13,7 @@ self.addEventListener("activate", event => {
.then(keys =>
Promise.all(
keys.map(key => {
console.log(`Deleting cache ${key}`);
console.log(`Sletter mellom-lager på nøkkel ${key}`);
return caches.delete(key);
})
)
@@ -25,18 +26,29 @@ self.addEventListener("activate", event => {
.then(keys =>
Promise.all(
keys.map(key => {
console.log(`Deleting cache ${key}`);
console.log(`Sletter mellom-lager på nøkkel ${key}`);
return caches.delete(key);
})
)
)
);
event.waitUntil(
caches.open(CACHE_NAME).then(cache => {
console.log("Legger til cache", cache);
return cache.addAll(STATIC_CACHE_URLS);
})
);
});
self.addEventListener("install", event => {
console.log("Arbeids arbeideren installerer seg.");
self.skipWaiting();
event.waitUntil(
caches.open(CACHE_NAME).then(cache => cache.addAll(STATIC_CACHE_URLS))
caches.open(CACHE_NAME).then(cache => {
console.log("Legger til cache", cache);
return cache.addAll(STATIC_CACHE_URLS);
})
);
});

View File

@@ -81,7 +81,7 @@ app.use("/api/", updateApi);
app.use("/api/", retrieveApi);
app.use("/service-worker.js", function(req, res) {
res.sendFile(path.join(__dirname, "public/service-worker.js"));
res.sendFile(path.join(__dirname, "public/sw/serviceWorker.js"));
});
app.listen(30030);

View File

@@ -9,6 +9,7 @@ if (environment === "development") {
let prodConfig = require("./config/webpack.config.prod");
prodConfig = merge(prodConfig, require("./config/vinlottis.config.js"));
let serviceWorkerConfig = require("./config/service-worker.config.js");
module.exports = prodConfig;
module.exports = [prodConfig, serviceWorkerConfig];
}