diff --git a/web/package.json b/web/package.json --- a/web/package.json +++ b/web/package.json @@ -6,7 +6,7 @@ "license": "BSD-3-Clause", "scripts": { "clean": "rm -rf dist/ && rm -rf node_modules/", - "dev": "yarn concurrently --names=\"NODESSR,BROWSER\" -c \"bgBlue.bold,bgMagenta.bold\" \"yarn webpack --config webpack.config.cjs --config-name=server --watch\" \"yarn webpack-dev-server --config webpack.config.cjs --config-name=browser\"", + "dev": "yarn concurrently --names=\"NODESSR,BROWSER,WORKERS\" -c \"bgBlue.bold,bgMagenta.bold,bgRed.bold\" \"yarn webpack --config webpack.config.cjs --config-name=server --watch\" \"yarn webpack-dev-server --config webpack.config.cjs --config-name=browser\" \"yarn webpack --config webpack.config.cjs --config-name=webworkers --watch\"", "prod": "yarn webpack --config webpack.config.cjs --env prod --progress", "test": "jest" }, diff --git a/web/push-notif/sw.js b/web/push-notif/sw.js new file mode 100644 --- /dev/null +++ b/web/push-notif/sw.js @@ -0,0 +1,9 @@ +// @flow + +self.addEventListener('install', () => { + console.log('service worker installed'); +}); + +self.addEventListener('activate', () => { + console.log('service worker activated'); +}); diff --git a/web/webpack.config.cjs b/web/webpack.config.cjs --- a/web/webpack.config.cjs +++ b/web/webpack.config.cjs @@ -84,6 +84,18 @@ }, }; +const baseWebWorkersConfig = { + name: 'webworkers', + target: 'webworker', + entry: { + pushNotif: './push-notif/sw.js', + }, + output: { + filename: '[name].build.cjs', + path: path.join(__dirname, 'dist', 'webworkers'), + }, +}; + module.exports = function (env) { const browserConfig = env.prod ? createProdBrowserConfig(baseProdBrowserConfig, babelConfig) @@ -96,5 +108,9 @@ ...nodeConfig, mode: env.prod ? 'production' : 'development', }; - return [browserConfig, nodeServerRenderingConfig]; + const webWorkersConfig = { + ...baseWebWorkersConfig, + mode: env === 'prod' ? 'production' : 'development', + }; + return [browserConfig, nodeServerRenderingConfig, webWorkersConfig]; };