webpack.config.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /* eslint-env node */
  2. /* eslint import/no-nodejs-modules:0 */
  3. import fs from 'fs';
  4. import path from 'path';
  5. import CompressionPlugin from 'compression-webpack-plugin';
  6. import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
  7. import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
  8. import MiniCssExtractPlugin from 'mini-css-extract-plugin';
  9. import webpack from 'webpack';
  10. import {Configuration as DevServerConfig} from 'webpack-dev-server';
  11. import FixStyleOnlyEntriesPlugin from 'webpack-remove-empty-scripts';
  12. import IntegrationDocsFetchPlugin from './build-utils/integration-docs-fetch-plugin';
  13. import LastBuiltPlugin from './build-utils/last-built-plugin';
  14. import SentryInstrumentation from './build-utils/sentry-instrumentation';
  15. import babelConfig from './babel.config';
  16. /**
  17. * Merges the devServer config into the webpack config
  18. *
  19. * See: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43232
  20. */
  21. interface Configuration extends webpack.Configuration {
  22. devServer?: DevServerConfig;
  23. }
  24. const {env} = process;
  25. // Environment configuration
  26. env.NODE_ENV = env.NODE_ENV ?? 'development';
  27. const IS_PRODUCTION = env.NODE_ENV === 'production';
  28. const IS_TEST = env.NODE_ENV === 'test' || !!env.TEST_SUITE;
  29. const IS_STORYBOOK = env.STORYBOOK_BUILD === '1';
  30. // This is used to stop rendering dynamic content for tests/snapshots
  31. // We want it in the case where we are running tests and it is in CI,
  32. // this should not happen in local
  33. const IS_CI = !!env.CI;
  34. // We intentionally build in production mode for acceptance tests, so we explicitly use an env var to
  35. // say that the bundle will be used in acceptance tests. This affects webpack plugins and components
  36. // with dynamic data that render differently statically in tests.
  37. //
  38. // Note, cannot assume it is an acceptance test if `IS_CI` is true, as our image builds has the
  39. // `CI` env var set.
  40. const IS_ACCEPTANCE_TEST = !!env.IS_ACCEPTANCE_TEST;
  41. const IS_DEPLOY_PREVIEW = !!env.NOW_GITHUB_DEPLOYMENT;
  42. const IS_UI_DEV_ONLY = !!env.SENTRY_UI_DEV_ONLY;
  43. const DEV_MODE = !(IS_PRODUCTION || IS_CI);
  44. const WEBPACK_MODE: Configuration['mode'] = IS_PRODUCTION ? 'production' : 'development';
  45. // Environment variables that are used by other tooling and should
  46. // not be user configurable.
  47. //
  48. // Ports used by webpack dev server to proxy to backend and webpack
  49. const SENTRY_BACKEND_PORT = env.SENTRY_BACKEND_PORT;
  50. const SENTRY_WEBPACK_PROXY_HOST = env.SENTRY_WEBPACK_PROXY_HOST;
  51. const SENTRY_WEBPACK_PROXY_PORT = env.SENTRY_WEBPACK_PROXY_PORT;
  52. const SENTRY_RELEASE_VERSION = env.SENTRY_RELEASE_VERSION;
  53. // Used by sentry devserver runner to force using webpack-dev-server
  54. const FORCE_WEBPACK_DEV_SERVER = !!env.FORCE_WEBPACK_DEV_SERVER;
  55. const HAS_WEBPACK_DEV_SERVER_CONFIG =
  56. !!SENTRY_BACKEND_PORT && !!SENTRY_WEBPACK_PROXY_PORT;
  57. // User/tooling configurable environment variables
  58. const NO_DEV_SERVER = !!env.NO_DEV_SERVER; // Do not run webpack dev server
  59. const SHOULD_FORK_TS = DEV_MODE && !env.NO_TS_FORK; // Do not run fork-ts plugin (or if not dev env)
  60. const SHOULD_HOT_MODULE_RELOAD = DEV_MODE && !!env.SENTRY_UI_HOT_RELOAD;
  61. // Deploy previews are built using vercel. We can check if we're in vercel's
  62. // build process by checking the existence of the PULL_REQUEST env var.
  63. const DEPLOY_PREVIEW_CONFIG = IS_DEPLOY_PREVIEW && {
  64. branch: env.NOW_GITHUB_COMMIT_REF,
  65. commitSha: env.NOW_GITHUB_COMMIT_SHA,
  66. githubOrg: env.NOW_GITHUB_COMMIT_ORG,
  67. githubRepo: env.NOW_GITHUB_COMMIT_REPO,
  68. };
  69. // When deploy previews are enabled always enable experimental SPA mode --
  70. // deploy previews are served standalone. Otherwise fallback to the environment
  71. // configuration.
  72. const SENTRY_EXPERIMENTAL_SPA =
  73. !DEPLOY_PREVIEW_CONFIG && !IS_UI_DEV_ONLY ? !!env.SENTRY_EXPERIMENTAL_SPA : true;
  74. // We should only read from the SENTRY_SPA_DSN env variable if SENTRY_EXPERIMENTAL_SPA
  75. // is true. This is to make sure we can validate that the experimental SPA mode is
  76. // working properly.
  77. const SENTRY_SPA_DSN = SENTRY_EXPERIMENTAL_SPA ? env.SENTRY_SPA_DSN : undefined;
  78. // this is the path to the django "sentry" app, we output the webpack build here to `dist`
  79. // so that `django collectstatic` and so that we can serve the post-webpack bundles
  80. const sentryDjangoAppPath = path.join(__dirname, 'src/sentry/static/sentry');
  81. const distPath = env.SENTRY_STATIC_DIST_PATH || path.join(sentryDjangoAppPath, 'dist');
  82. const staticPrefix = path.join(__dirname, 'static');
  83. // Locale file extraction build step
  84. if (env.SENTRY_EXTRACT_TRANSLATIONS === '1') {
  85. babelConfig.plugins?.push([
  86. 'module:babel-gettext-extractor',
  87. {
  88. fileName: 'build/javascript.po',
  89. baseDirectory: path.join(__dirname),
  90. functionNames: {
  91. gettext: ['msgid'],
  92. ngettext: ['msgid', 'msgid_plural', 'count'],
  93. gettextComponentTemplate: ['msgid'],
  94. t: ['msgid'],
  95. tn: ['msgid', 'msgid_plural', 'count'],
  96. tct: ['msgid'],
  97. },
  98. },
  99. ]);
  100. }
  101. // Locale compilation and optimizations.
  102. //
  103. // Locales are code-split from the app and vendor chunk into separate chunks
  104. // that will be loaded by layout.html depending on the users configured locale.
  105. //
  106. // Code splitting happens using the splitChunks plugin, configured under the
  107. // `optimization` key of the webpack module. We create chunk (cache) groups for
  108. // each of our supported locales and extract the PO files and moment.js locale
  109. // files into each chunk.
  110. //
  111. // A plugin is used to remove the locale chunks from the app entry's chunk
  112. // dependency list, so that our compiled bundle does not expect that *all*
  113. // locale chunks must be loaded
  114. const localeCatalogPath = path.join(
  115. __dirname,
  116. 'src',
  117. 'sentry',
  118. 'locale',
  119. 'catalogs.json'
  120. );
  121. type LocaleCatalog = {
  122. supported_locales: string[];
  123. };
  124. const localeCatalog: LocaleCatalog = JSON.parse(
  125. fs.readFileSync(localeCatalogPath, 'utf8')
  126. );
  127. // Translates a locale name to a language code.
  128. //
  129. // * po files are kept in a directory represented by the locale name [0]
  130. // * moment.js locales are stored as language code files
  131. //
  132. // [0] https://docs.djangoproject.com/en/2.1/topics/i18n/#term-locale-name
  133. const localeToLanguage = (locale: string) => locale.toLowerCase().replace('_', '-');
  134. const supportedLocales = localeCatalog.supported_locales;
  135. const supportedLanguages = supportedLocales.map(localeToLanguage);
  136. type CacheGroups = Exclude<
  137. NonNullable<Configuration['optimization']>['splitChunks'],
  138. false | undefined
  139. >['cacheGroups'];
  140. type CacheGroupTest = (
  141. module: webpack.Module,
  142. context: Parameters<webpack.optimize.SplitChunksPlugin['options']['getCacheGroups']>[1]
  143. ) => boolean;
  144. // A mapping of chunk groups used for locale code splitting
  145. const localeChunkGroups: CacheGroups = {};
  146. supportedLocales
  147. // No need to split the english locale out as it will be completely empty and
  148. // is not included in the django layout.html.
  149. .filter(l => l !== 'en')
  150. .forEach(locale => {
  151. const language = localeToLanguage(locale);
  152. const group = `locale/${language}`;
  153. // List of module path tests to group into locale chunks
  154. const localeGroupTests = [
  155. new RegExp(`locale\\/${locale}\\/.*\\.po$`),
  156. new RegExp(`moment\\/locale\\/${language}\\.js$`),
  157. ];
  158. // module test taken from [0] and modified to support testing against
  159. // multiple expressions.
  160. //
  161. // [0] https://github.com/webpack/webpack/blob/7a6a71f1e9349f86833de12a673805621f0fc6f6/lib/optimize/SplitChunksPlugin.js#L309-L320
  162. const groupTest: CacheGroupTest = (module, {chunkGraph}) =>
  163. localeGroupTests.some(pattern =>
  164. pattern.test(module?.nameForCondition?.() ?? '')
  165. ? true
  166. : chunkGraph.getModuleChunks(module).some(c => c.name && pattern.test(c.name))
  167. );
  168. // We are defining a chunk that combines the django language files with
  169. // moment's locales as if you want one, you will want the other.
  170. //
  171. // In the application code you will still need to import via their module
  172. // paths and not the chunk name
  173. localeChunkGroups[group] = {
  174. chunks: 'async',
  175. name: group,
  176. test: groupTest,
  177. enforce: true,
  178. };
  179. });
  180. const babelOptions = {...babelConfig, cacheDirectory: true};
  181. const babelLoaderConfig = {
  182. loader: 'babel-loader',
  183. options: babelOptions,
  184. };
  185. /**
  186. * Main Webpack config for Sentry React SPA.
  187. */
  188. let appConfig: Configuration = {
  189. mode: WEBPACK_MODE,
  190. entry: {
  191. /**
  192. * Main Sentry SPA
  193. *
  194. * The order here matters for `getsentry`
  195. */
  196. app: ['sentry/utils/statics-setup', 'sentry'],
  197. /**
  198. * Pipeline View for integrations
  199. */
  200. pipeline: ['sentry/utils/statics-setup', 'sentry/views/integrationPipeline'],
  201. /**
  202. * Legacy CSS Webpack appConfig for Django-powered views.
  203. * This generates a single "sentry.css" file that imports ALL component styles
  204. * for use on Django-powered pages.
  205. */
  206. sentry: 'less/sentry.less',
  207. },
  208. context: staticPrefix,
  209. module: {
  210. /**
  211. * XXX: Modifying the order/contents of these rules may break `getsentry`
  212. * Please remember to test it.
  213. */
  214. rules: [
  215. {
  216. test: /\.[tj]sx?$/,
  217. include: [staticPrefix],
  218. exclude: /(vendor|node_modules|dist)/,
  219. use: babelLoaderConfig,
  220. },
  221. {
  222. test: /\.po$/,
  223. use: {
  224. loader: 'po-catalog-loader',
  225. options: {
  226. referenceExtensions: ['.js', '.jsx', '.tsx'],
  227. domain: 'sentry',
  228. },
  229. },
  230. },
  231. {
  232. test: /\.pegjs/,
  233. use: {loader: 'pegjs-loader'},
  234. },
  235. {
  236. test: /\.css/,
  237. use: ['style-loader', 'css-loader'],
  238. },
  239. {
  240. test: /\.less$/,
  241. include: [staticPrefix],
  242. use: [
  243. {
  244. loader: MiniCssExtractPlugin.loader,
  245. options: {
  246. publicPath: 'auto',
  247. },
  248. },
  249. 'css-loader',
  250. 'less-loader',
  251. ],
  252. },
  253. {
  254. test: /\.(woff|woff2|ttf|eot|svg|png|gif|ico|jpg|mp4)($|\?)/,
  255. type: 'asset',
  256. },
  257. ],
  258. noParse: [
  259. // don't parse known, pre-built javascript files (improves webpack perf)
  260. /jed\/jed\.js/,
  261. /marked\/lib\/marked\.js/,
  262. /terser\/dist\/bundle\.min\.js/,
  263. ],
  264. },
  265. plugins: [
  266. // Do not bundle moment's locale files as we will lazy load them using
  267. // dynamic imports in the application code
  268. new webpack.IgnorePlugin({
  269. contextRegExp: /moment$/,
  270. resourceRegExp: /^\.\/locale$/,
  271. }),
  272. /**
  273. * TODO(epurkhiser): Figure out if we still need these
  274. */
  275. new webpack.ProvidePlugin({
  276. process: 'process/browser',
  277. Buffer: ['buffer', 'Buffer'],
  278. }),
  279. /**
  280. * Extract CSS into separate files.
  281. */
  282. new MiniCssExtractPlugin({
  283. // We want the sentry css file to be unversioned for frontend-only deploys
  284. // We will cache using `Cache-Control` headers
  285. filename: 'entrypoints/[name].css',
  286. }),
  287. /**
  288. * Defines environment specific flags.
  289. */
  290. new webpack.DefinePlugin({
  291. 'process.env': {
  292. NODE_ENV: JSON.stringify(env.NODE_ENV),
  293. IS_ACCEPTANCE_TEST: JSON.stringify(IS_ACCEPTANCE_TEST),
  294. DEPLOY_PREVIEW_CONFIG: JSON.stringify(DEPLOY_PREVIEW_CONFIG),
  295. EXPERIMENTAL_SPA: JSON.stringify(SENTRY_EXPERIMENTAL_SPA),
  296. SPA_DSN: JSON.stringify(SENTRY_SPA_DSN),
  297. SENTRY_RELEASE_VERSION: JSON.stringify(SENTRY_RELEASE_VERSION),
  298. },
  299. }),
  300. /**
  301. * This removes empty js files for style only entries (e.g. sentry.less)
  302. */
  303. new FixStyleOnlyEntriesPlugin({verbose: false}),
  304. /**
  305. * Adds build time measurement instrumentation, which will be reported back
  306. * to sentry
  307. */
  308. new SentryInstrumentation(),
  309. ...(SHOULD_FORK_TS
  310. ? [
  311. new ForkTsCheckerWebpackPlugin({
  312. typescript: {
  313. configFile: path.resolve(__dirname, './config/tsconfig.build.json'),
  314. configOverwrite: {
  315. compilerOptions: {incremental: true},
  316. },
  317. },
  318. logger: {devServer: false},
  319. }),
  320. ]
  321. : []),
  322. /**
  323. * Restrict translation files that are pulled in through app/translations.jsx
  324. * and through moment/locale/* to only those which we create bundles for via
  325. * locale/catalogs.json.
  326. *
  327. * Without this, webpack will still output all of the unused locale files despite
  328. * the application never loading any of them.
  329. */
  330. new webpack.ContextReplacementPlugin(
  331. /sentry-locale$/,
  332. path.join(__dirname, 'src', 'sentry', 'locale', path.sep),
  333. true,
  334. new RegExp(`(${supportedLocales.join('|')})/.*\\.po$`)
  335. ),
  336. new webpack.ContextReplacementPlugin(
  337. /moment\/locale/,
  338. new RegExp(`(${supportedLanguages.join('|')})\\.js$`)
  339. ),
  340. ],
  341. resolve: {
  342. alias: {
  343. 'react-dom$': 'react-dom/profiling',
  344. 'scheduler/tracing': 'scheduler/tracing-profiling',
  345. sentry: path.join(staticPrefix, 'app'),
  346. 'sentry-images': path.join(staticPrefix, 'images'),
  347. 'sentry-logos': path.join(sentryDjangoAppPath, 'images', 'logos'),
  348. 'sentry-fonts': path.join(staticPrefix, 'fonts'),
  349. // Aliasing this for getsentry's build, otherwise `less/select2` will not be able
  350. // to be resolved
  351. less: path.join(staticPrefix, 'less'),
  352. 'sentry-test': path.join(__dirname, 'tests', 'js', 'sentry-test'),
  353. 'sentry-locale': path.join(__dirname, 'src', 'sentry', 'locale'),
  354. 'ios-device-list': path.join(
  355. __dirname,
  356. 'node_modules',
  357. 'ios-device-list',
  358. 'dist',
  359. 'ios-device-list.min.js'
  360. ),
  361. },
  362. fallback: {
  363. vm: false,
  364. stream: false,
  365. crypto: require.resolve('crypto-browserify'),
  366. // `yarn why` says this is only needed in dev deps
  367. string_decoder: false,
  368. },
  369. modules: ['node_modules'],
  370. extensions: ['.jsx', '.js', '.json', '.ts', '.tsx', '.less'],
  371. },
  372. output: {
  373. clean: true, // Clean the output directory before emit.
  374. path: distPath,
  375. publicPath: '',
  376. filename: 'entrypoints/[name].js',
  377. chunkFilename: 'chunks/[name].[contenthash].js',
  378. sourceMapFilename: 'sourcemaps/[name].[contenthash].js.map',
  379. assetModuleFilename: 'assets/[name].[contenthash][ext]',
  380. },
  381. optimization: {
  382. chunkIds: 'named',
  383. moduleIds: 'named',
  384. splitChunks: {
  385. // Only affect async chunks, otherwise webpack could potentially split our initial chunks
  386. // Which means the app will not load because we'd need these additional chunks to be loaded in our
  387. // django template.
  388. chunks: 'async',
  389. maxInitialRequests: 10, // (default: 30)
  390. maxAsyncRequests: 10, // (default: 30)
  391. cacheGroups: {
  392. ...localeChunkGroups,
  393. },
  394. },
  395. // This only runs in production mode
  396. // Grabbed this example from https://github.com/webpack-contrib/css-minimizer-webpack-plugin
  397. minimizer: ['...', new CssMinimizerPlugin()],
  398. },
  399. devtool: IS_PRODUCTION ? 'source-map' : 'eval-cheap-module-source-map',
  400. };
  401. if (IS_TEST || IS_ACCEPTANCE_TEST || IS_STORYBOOK) {
  402. appConfig.resolve!.alias!['integration-docs-platforms'] = path.join(
  403. __dirname,
  404. 'tests/fixtures/integration-docs/_platforms.json'
  405. );
  406. } else {
  407. const plugin = new IntegrationDocsFetchPlugin({basePath: __dirname});
  408. appConfig.plugins?.push(plugin);
  409. appConfig.resolve!.alias!['integration-docs-platforms'] = plugin.modulePath;
  410. }
  411. if (IS_ACCEPTANCE_TEST) {
  412. appConfig.plugins?.push(new LastBuiltPlugin({basePath: __dirname}));
  413. }
  414. // Dev only! Hot module reloading
  415. if (
  416. FORCE_WEBPACK_DEV_SERVER ||
  417. (HAS_WEBPACK_DEV_SERVER_CONFIG && !NO_DEV_SERVER) ||
  418. IS_UI_DEV_ONLY
  419. ) {
  420. if (SHOULD_HOT_MODULE_RELOAD) {
  421. // Hot reload react components on save
  422. // We include the library here as to not break docker/google cloud builds
  423. // since we do not install devDeps there.
  424. const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
  425. appConfig.plugins?.push(new ReactRefreshWebpackPlugin());
  426. }
  427. appConfig.devServer = {
  428. headers: {
  429. 'Access-Control-Allow-Origin': '*',
  430. 'Access-Control-Allow-Credentials': 'true',
  431. },
  432. // Required for getsentry
  433. disableHostCheck: true,
  434. contentBase: './src/sentry/static/sentry',
  435. host: SENTRY_WEBPACK_PROXY_HOST,
  436. hot: true,
  437. // If below is false, will reload on errors
  438. hotOnly: true,
  439. port: Number(SENTRY_WEBPACK_PROXY_PORT),
  440. stats: 'errors-only',
  441. overlay: false,
  442. watchOptions: {
  443. ignored: ['node_modules'],
  444. },
  445. };
  446. if (!IS_UI_DEV_ONLY) {
  447. // This proxies to local backend server
  448. const backendAddress = `http://localhost:${SENTRY_BACKEND_PORT}/`;
  449. const relayAddress = 'http://127.0.0.1:7899';
  450. appConfig.devServer = {
  451. ...appConfig.devServer,
  452. publicPath: '/_static/dist/sentry',
  453. // syntax for matching is using https://www.npmjs.com/package/micromatch
  454. proxy: {
  455. '/api/store/**': relayAddress,
  456. '/api/{1..9}*({0..9})/**': relayAddress,
  457. '/api/0/relays/outcomes/': relayAddress,
  458. '!/_static/dist/sentry/**': backendAddress,
  459. },
  460. };
  461. }
  462. }
  463. // XXX(epurkhiser): Sentry (development) can be run in an experimental
  464. // pure-SPA mode, where ONLY /api* requests are proxied directly to the API
  465. // backend (in this case, sentry.io), otherwise ALL requests are rewritten
  466. // to a development index.html -- thus, completely separating the frontend
  467. // from serving any pages through the backend.
  468. //
  469. // THIS IS EXPERIMENTAL and has limitations (e.g. you can't use SSO)
  470. //
  471. // Various sentry pages still rely on django to serve html views.
  472. if (IS_UI_DEV_ONLY) {
  473. // Try and load certificates from mkcert if available. Use $ yarn mkcert-localhost
  474. const certPath = path.join(__dirname, 'config');
  475. const https = !fs.existsSync(path.join(certPath, 'localhost.pem'))
  476. ? true
  477. : {
  478. key: fs.readFileSync(path.join(certPath, 'localhost-key.pem')),
  479. cert: fs.readFileSync(path.join(certPath, 'localhost.pem')),
  480. };
  481. appConfig.devServer = {
  482. ...appConfig.devServer,
  483. compress: true,
  484. https,
  485. publicPath: '/_assets/',
  486. proxy: [
  487. {
  488. context: ['/api/', '/avatar/', '/organization-avatar/'],
  489. target: 'https://sentry.io',
  490. secure: false,
  491. changeOrigin: true,
  492. headers: {
  493. Referer: 'https://sentry.io/',
  494. },
  495. },
  496. ],
  497. historyApiFallback: {
  498. rewrites: [{from: /^\/.*$/, to: '/_assets/index.html'}],
  499. },
  500. };
  501. appConfig.optimization = {
  502. runtimeChunk: 'single',
  503. };
  504. // TODO: remove target "web" when upgrading to webpack-dev-server v4
  505. appConfig.target = 'web';
  506. }
  507. if (IS_UI_DEV_ONLY || IS_DEPLOY_PREVIEW) {
  508. appConfig.output!.publicPath = '/_assets/';
  509. /**
  510. * Generate a index.html file used for running the app in pure client mode.
  511. * This is currently used for PR deploy previews, where only the frontend
  512. * is deployed.
  513. */
  514. const HtmlWebpackPlugin = require('html-webpack-plugin');
  515. appConfig.plugins?.push(
  516. new HtmlWebpackPlugin({
  517. // Local dev vs vercel slightly differs...
  518. ...(IS_UI_DEV_ONLY
  519. ? {devServer: `https://localhost:${SENTRY_WEBPACK_PROXY_PORT}`}
  520. : {}),
  521. favicon: path.resolve(sentryDjangoAppPath, 'images', 'favicon_dev.png'),
  522. template: path.resolve(staticPrefix, 'index.ejs'),
  523. mobile: true,
  524. excludeChunks: ['pipeline'],
  525. title: 'Sentry',
  526. })
  527. );
  528. }
  529. const minificationPlugins = [
  530. // This compression-webpack-plugin generates pre-compressed files
  531. // ending in .gz, to be picked up and served by our internal static media
  532. // server as well as nginx when paired with the gzip_static module.
  533. //
  534. // TODO(ts): The current @types/compression-webpack-plugin is still targeting
  535. // webpack@4, for now we just as any it.
  536. new CompressionPlugin({
  537. algorithm: 'gzip',
  538. test: /\.(js|map|css|svg|html|txt|ico|eot|ttf)$/,
  539. }) as any,
  540. // NOTE: In production mode webpack will automatically minify javascript
  541. // using the TerserWebpackPlugin.
  542. ];
  543. if (IS_PRODUCTION) {
  544. // NOTE: can't do plugins.push(Array) because webpack/webpack#2217
  545. minificationPlugins.forEach(plugin => appConfig.plugins?.push(plugin));
  546. }
  547. // Cache webpack builds
  548. if (env.WEBPACK_CACHE_PATH) {
  549. appConfig.cache = {
  550. type: 'filesystem',
  551. cacheLocation: path.resolve(__dirname, env.WEBPACK_CACHE_PATH),
  552. buildDependencies: {
  553. // This makes all dependencies of this file - build dependencies
  554. config: [__filename],
  555. // By default webpack and loaders are build dependencies
  556. },
  557. };
  558. }
  559. if (env.MEASURE) {
  560. const SpeedMeasurePlugin = require('speed-measure-webpack-plugin');
  561. const smp = new SpeedMeasurePlugin();
  562. appConfig = smp.wrap(appConfig);
  563. }
  564. export default appConfig;