webpack.config.js 19 KB

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