webpack.config.js 19 KB

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