Page MenuHomePhabricator

D6715.diff
No OneTemporary

D6715.diff

diff --git a/lib/webpack/shared.cjs b/lib/webpack/shared.cjs
--- a/lib/webpack/shared.cjs
+++ b/lib/webpack/shared.cjs
@@ -251,8 +251,30 @@
};
}
+function createWebWorkersConfig(env, baseConfig, babelConfig) {
+ return {
+ ...baseConfig,
+ name: 'webworkers',
+ target: 'webworker',
+ mode: env.prod ? 'production' : 'development',
+ module: {
+ rules: [getBrowserBabelRule(babelConfig)],
+ },
+ plugins: [
+ ...sharedPlugins,
+ new webpack.DefinePlugin({
+ 'process.env': {
+ NODE_ENV: JSON.stringify(env.prod ? 'production' : 'development'),
+ BROWSER: true,
+ },
+ }),
+ ],
+ };
+}
+
module.exports = {
createProdBrowserConfig,
createDevBrowserConfig,
createNodeServerRenderingConfig,
+ createWebWorkersConfig,
};
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,bgCyan.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/service-worker.js b/web/push-notif/service-worker.js
new file mode 100644
--- /dev/null
+++ b/web/push-notif/service-worker.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
@@ -6,6 +6,7 @@
createProdBrowserConfig,
createDevBrowserConfig,
createNodeServerRenderingConfig,
+ createWebWorkersConfig,
} = require('lib/webpack/shared.cjs');
const babelConfig = require('./babel.config.cjs');
@@ -84,6 +85,16 @@
},
};
+const baseWebWorkersConfig = {
+ entry: {
+ pushNotif: './push-notif/service-worker.js',
+ },
+ output: {
+ filename: '[name].build.js',
+ path: path.join(__dirname, 'dist', 'webworkers'),
+ },
+};
+
module.exports = function (env) {
const browserConfig = env.prod
? createProdBrowserConfig(baseProdBrowserConfig, babelConfig)
@@ -96,5 +107,10 @@
...nodeConfig,
mode: env.prod ? 'production' : 'development',
};
- return [browserConfig, nodeServerRenderingConfig];
+ const webWorkersConfig = createWebWorkersConfig(
+ env,
+ baseWebWorkersConfig,
+ babelConfig,
+ );
+ return [browserConfig, nodeServerRenderingConfig, webWorkersConfig];
};

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 22, 9:12 AM (13 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2690697
Default Alt Text
D6715.diff (3 KB)

Event Timeline