Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

webpack_public_path: Replace with webpack 5 publicPath: "auto" setting.

Anders Kaseorg94934f49f914
diff --git a/tools/test-js-with-node b/tools/test-js-with-node
index 15c05e76bb9..ed70721de3a 100755
--- a/tools/test-js-with-node
+++ b/tools/test-js-with-node
@@ -273,7 +273,6 @@ EXEMPT_FILES = make_set(
"web/src/user_topics.ts",
"web/src/user_topics_ui.js",
"web/src/views_util.js",
- "web/src/webpack_public_path.js",
"web/src/zcommand.js",
"web/src/zform.js",
"web/src/zulip.js",
diff --git a/web/src/bundles/common.ts b/web/src/bundles/common.ts
index bd09c56b490..0ff5ec97fca 100644
--- a/web/src/bundles/common.ts
+++ b/web/src/bundles/common.ts
@@ -1,5 +1,4 @@
import "../sentry";
-import "../webpack_public_path";
import "../../debug-require";
import "../alert_popup";
import "../csrf";
diff --git a/web/src/page_params.ts b/web/src/page_params.ts
index 2042aed8e3b..1a15f8bebef 100644
--- a/web/src/page_params.ts
+++ b/web/src/page_params.ts
@@ -90,7 +90,6 @@ export const page_params: {
show_webathena: boolean;
translation_data: Record<string, string>;
user_id: number | undefined;
- webpack_public_path: string;
zulip_merge_base: string;
zulip_plan_is_not_limited: boolean;
zulip_version: string;
diff --git a/web/src/sentry.ts b/web/src/sentry.ts
index 4fb42b36b7c..fa6c18be12f 100644
--- a/web/src/sentry.ts
+++ b/web/src/sentry.ts
@@ -31,7 +31,12 @@ export function shouldCreateSpanForRequest(url: string): boolean {
}
if (page_params.server_sentry_dsn) {
- const url_matches = [/^\//, new RegExp("^" + _.escapeRegExp(page_params.webpack_public_path))];
+ const url_matches = [/^\//];
+ if (document.currentScript instanceof HTMLScriptElement) {
+ url_matches.push(
+ new RegExp("^" + _.escapeRegExp(new URL(".", document.currentScript.src).href)),
+ );
+ }
if (page_params.realm_uri !== undefined) {
url_matches.push(new RegExp("^" + _.escapeRegExp(page_params.realm_uri) + "/"));
}
diff --git a/web/src/webpack_public_path.js b/web/src/webpack_public_path.js
deleted file mode 100644
index b3fc363d35f..00000000000
--- a/web/src/webpack_public_path.js
+++ /dev/null
@@ -1,11 +0,0 @@
-/* eslint-env commonjs */
-// eslint-disable-next-line no-unused-vars
-/* global __webpack_public_path__:writable */
-
-"use strict";
-
-const {page_params} = require("./page_params");
-
-// Webpack exposes this global for dynamic configuration of publicPath.
-// https://webpack.js.org/guides/public-path/#on-the-fly
-__webpack_public_path__ = page_params.webpack_public_path;
diff --git a/web/webpack.config.ts b/web/webpack.config.ts
index ce435da9eb7..702c907b31a 100644
--- a/web/webpack.config.ts
+++ b/web/webpack.config.ts
@@ -163,7 +163,7 @@ export default (
},
output: {
path: path.resolve(__dirname, "../static/webpack-bundles"),
- publicPath: "",
+ publicPath: "auto",
filename: production ? "[name].[contenthash].js" : "[name].js",
assetModuleFilename: production
? "files/[name].[hash][ext][query]"
diff --git a/zerver/context_processors.py b/zerver/context_processors.py
index ef47311405f..500229d8669 100644
--- a/zerver/context_processors.py
+++ b/zerver/context_processors.py
@@ -2,7 +2,6 @@ from typing import Any, Dict, Mapping, Optional
from urllib.parse import urljoin
from django.conf import settings
-from django.contrib.staticfiles.storage import staticfiles_storage
from django.http import HttpRequest
from django.utils.html import escape
from django.utils.safestring import SafeString
@@ -32,7 +31,6 @@ from zproject.config import get_config
DEFAULT_PAGE_PARAMS: Mapping[str, Any] = {
"development_environment": settings.DEVELOPMENT,
- "webpack_public_path": staticfiles_storage.url(settings.WEBPACK_BUNDLES),
}
diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py
index 5e02919f400..31f65e2df9f 100644
--- a/zerver/tests/test_home.py
+++ b/zerver/tests/test_home.py
@@ -226,7 +226,6 @@ class HomeTest(ZulipTestCase):
"user_status",
"user_topics",
"warn_no_email",
- "webpack_public_path",
"zulip_feature_level",
"zulip_merge_base",
"zulip_plan_is_not_limited",
@@ -368,7 +367,6 @@ class HomeTest(ZulipTestCase):
"two_fa_enabled",
"two_fa_enabled_user",
"warn_no_email",
- "webpack_public_path",
]
self.assertEqual(actual_keys, expected_keys)