From 4575a4f93f6f3d808b45e35cff4462f833a7e1f7 Mon Sep 17 00:00:00 2001 From: legendecas Date: Wed, 23 Jun 2021 15:26:09 +0800 Subject: [PATCH 1/2] Fix Web Workers compatibility Latest Webpack generated dist files no longder reference "window". Thus those generated files are compatible with Web Workers. --- browser/package.json | 9 ++++++--- browser/webpack.config.js | 9 ++++++--- browser/webpack.mocha.js | 11 ++++++++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/browser/package.json b/browser/package.json index 854e1379b..07f0fe277 100755 --- a/browser/package.json +++ b/browser/package.json @@ -10,17 +10,20 @@ "@babel/core": "^7.4.5", "@babel/plugin-proposal-class-properties": "^7.7.4", "@babel/preset-env": "^7.4.5", + "assert": "^2.0.0", "babel-loader": "^8.0.6", "karma": "^4.2.0", "karma-chrome-launcher": "^3.0.0", "karma-mocha": "^1.3.0", "karma-sourcemap-loader": "^0.3.7", - "karma-webpack": "^4.0.2", + "karma-webpack": "^5.0.0", "mocha": "^6.2.0", "mocha-loader": "^2.0.1", "null-loader": "^3.0.0", - "webpack": "^4.35.2", + "process": "^0.11.10", + "util": "^0.12.4", + "webpack": "^5.40.0", "webpack-bundle-analyzer": "^3.4.1", - "webpack-cli": "^3.3.5" + "webpack-cli": "^4.7.2" } } diff --git a/browser/webpack.config.js b/browser/webpack.config.js index 9bc286dde..b5242c367 100755 --- a/browser/webpack.config.js +++ b/browser/webpack.config.js @@ -57,8 +57,11 @@ module.exports = { } ] }, - node: { - url: 'empty', - util: 'empty' + node: false, + resolve: { + fallback: { + url: false, + util: false, + } } }; diff --git a/browser/webpack.mocha.js b/browser/webpack.mocha.js index 19257d38a..fe59cad1e 100755 --- a/browser/webpack.mocha.js +++ b/browser/webpack.mocha.js @@ -1,4 +1,5 @@ const Path = require('path'); +const Webpack = require('webpack'); const WebpackConfig = require('./webpack.config'); @@ -16,6 +17,14 @@ WebpackConfig.module.rules[2].use.options.presets[0][1].exclude = [ '@babel/plugin-transform-regenerator' ]; -delete WebpackConfig.node.util; +// Used in testing. +WebpackConfig.plugins.push(new Webpack.ProvidePlugin({ + process: 'process/browser', +})); +WebpackConfig.node = { + global: true, +}; +WebpackConfig.resolve.fallback.util = require.resolve('util/'); +WebpackConfig.resolve.fallback.assert = require.resolve('assert/'); module.exports = WebpackConfig; From fbfd5d53bdeee92168f59815b10904d6245fdbcf Mon Sep 17 00:00:00 2001 From: legendecas Date: Mon, 5 Jul 2021 19:19:48 +0800 Subject: [PATCH 2/2] fixup! Fix Web Workers compatibility --- browser/webpack.mocha.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser/webpack.mocha.js b/browser/webpack.mocha.js index fe59cad1e..0b350bc2e 100755 --- a/browser/webpack.mocha.js +++ b/browser/webpack.mocha.js @@ -18,8 +18,8 @@ WebpackConfig.module.rules[2].use.options.presets[0][1].exclude = [ ]; // Used in testing. -WebpackConfig.plugins.push(new Webpack.ProvidePlugin({ - process: 'process/browser', +WebpackConfig.plugins.push(new Webpack.DefinePlugin({ + 'process.env.NODE_DEBUG': false, })); WebpackConfig.node = { global: true,