Skip to content

Commit

Permalink
Merge pull request #525 from bemusic/use-service-worker-plugin
Browse files Browse the repository at this point in the history
🏗️ Remove service-worker hack
  • Loading branch information
resir014 authored Dec 23, 2018
2 parents 71b9091 + 56bc60c commit 188e0ab
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 21 deletions.
29 changes: 23 additions & 6 deletions config/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { flowRight } from 'lodash'
import path from './path'
import webpack from 'webpack'
import webpackResolve from './webpackResolve'
import ServiceWorkerWebpackPlugin from 'serviceworker-webpack-plugin'

function generateBaseConfig() {
let config = {
Expand All @@ -19,7 +20,7 @@ function generateBaseConfig() {
},
devServer: {
contentBase: false,
publicPath: '/build/',
publicPath: '/',
stats: { colors: true, chunkModules: false },
},
module: {
Expand All @@ -40,6 +41,9 @@ function generateBaseConfig() {
context: process.cwd(),
},
}),
new ServiceWorkerWebpackPlugin({
entry: path('src/app/service-worker.js'),
}),
],
}

Expand Down Expand Up @@ -95,7 +99,12 @@ function generateLoadersConfig() {
},
{
test: /\.worker\.js$/,
use: { loader: 'worker-loader' },
use: {
loader: 'worker-loader',
options: {
name: 'build/[hash].worker.js',
},
},
},
{
test: /\.json$/,
Expand Down Expand Up @@ -170,21 +179,29 @@ function generateLoadersConfig() {
options: {
limit: 100000,
mimetype: 'image/png',
name: 'build/[hash].[ext]',
},
},
{
test: /\.jpg$/,
loader: 'file-loader',
options: {
name: 'build/[hash].[ext]',
},
},
{
test: /\.(?:mp3|mp4|ogg|m4a)$/,
loader: 'file-loader',
options: {
name: 'build/[hash].[ext]',
},
},
{
test: /\.(otf|eot|svg|ttf|woff|woff2)(?:$|\?)/,
loader: 'url-loader',
options: {
limit: 8192,
name: 'build/[hash].[ext]',
},
},
]
Expand All @@ -196,11 +213,11 @@ function applyWebConfig(config) {
boot: ['./boot'],
},
output: {
path: path('dist', 'build'),
publicPath: 'build/',
path: path('dist'),
publicPath: '/',
globalObject: 'this',
filename: '[name].js',
chunkFilename: '[name]-[chunkhash].js',
filename: 'build/[name].js',
chunkFilename: 'build/[name]-[chunkhash].js',
devtoolModuleFilenameTemplate: 'file://[absolute-resource-path]',
devtoolFallbackModuleFilenameTemplate:
'file://[absolute-resource-path]?[hash]',
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
"reselect": "^2.5.1",
"rxjs": "^5.5.12",
"screenfull": "^3.3.3",
"serviceworker-webpack-plugin": "^1.0.1",
"throat": "^2.0.2",
"timesynchro": "^1.0.1",
"updeep": "^0.16.0",
Expand Down
11 changes: 0 additions & 11 deletions public/sw-loader.js

This file was deleted.

5 changes: 2 additions & 3 deletions src/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PropTypes from 'prop-types'
import React from 'react'
import SCENE_MANAGER from 'bemuse/scene-manager'
import now from 'bemuse/utils/now'
import workerPath from 'bemuse/hacks/service-worker-url/index.loader.js!serviceworker-loader!./service-worker.js'
import serviceWorkerRuntime from 'serviceworker-webpack-plugin/lib/runtime'
import { OFFICIAL_SERVER_URL } from 'bemuse/music-collection'
import { createIO, createRun } from 'impure'
import {
Expand Down Expand Up @@ -113,8 +113,7 @@ function setupServiceWorker() {
}

function registerServiceWorker() {
const url = '/sw-loader.js?path=' + encodeURIComponent(workerPath)
return navigator.serviceWorker.register(url)
return serviceWorkerRuntime.register()
}

function trackFullscreenEvents() {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "./tsconfig.base.json",
"include": ["src/**/*"],
"include": ["src/**/*", "types/**/*"],
"exclude": ["node_modules", "website/node_modules"],
"compilerOptions": {
"baseUrl": ".",
Expand Down
4 changes: 4 additions & 0 deletions types/serviceworker-webpack-plugin.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module 'serviceworker-webpack-plugin/lib/runtime' {
const runtime: { register: () => Promise<ServiceWorkerRegistration> }
export default runtime
}
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12761,6 +12761,13 @@ serviceworker-loader@^0.1.0:
dependencies:
loader-utils "0.2.x"

serviceworker-webpack-plugin@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/serviceworker-webpack-plugin/-/serviceworker-webpack-plugin-1.0.1.tgz#481863288487e92da01d49745336c72ef8a6136b"
integrity sha512-VgDEkZ3pA0HajsRaWtl5w6bLxAXx0Y+4dm7YeTcIxVmvC9YXvstex38HOBDuYETeDS5fUlBy/47gC0QYBrG0nw==
dependencies:
minimatch "^3.0.4"

set-blocking@^2.0.0, set-blocking@~2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
Expand Down

0 comments on commit 188e0ab

Please sign in to comment.