webpack.config.js 19 KB

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