webpack.config.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. const path = require('path');
  2. // Generates a path to the output bundle to be loaded in the browser.
  3. const getOutputPath = (app, filename) => path.join('wagtail', app, 'static', `wagtail${app}`, 'js', filename);
  4. // Mapping from package name to exposed global variable.
  5. const exposedDependencies = {
  6. 'focus-trap-react': 'FocusTrapReact',
  7. 'react': 'React',
  8. 'react-dom': 'ReactDOM',
  9. 'react-transition-group/CSSTransitionGroup': 'CSSTransitionGroup',
  10. 'draft-js': 'DraftJS',
  11. };
  12. module.exports = function exports() {
  13. const entrypoints = [
  14. 'blocks/list',
  15. 'blocks/sequence',
  16. 'blocks/stream',
  17. 'blocks/struct',
  18. 'core',
  19. 'date-time-chooser',
  20. 'draftail',
  21. 'expanding_formset',
  22. 'filtered-select',
  23. 'hallo-bootstrap',
  24. 'hallo-plugins/hallo-hr',
  25. 'hallo-plugins/hallo-requireparagraphs',
  26. 'hallo-plugins/hallo-wagtaillink',
  27. 'lock-unlock-action',
  28. 'modal-workflow',
  29. 'page-chooser-modal',
  30. 'page-chooser',
  31. 'page-editor',
  32. 'privacy-switch',
  33. 'task-chooser-modal',
  34. 'task-chooser',
  35. 'userbar',
  36. 'wagtailadmin',
  37. 'workflow-action',
  38. 'workflow-status',
  39. ];
  40. const entry = {};
  41. entrypoints.forEach(moduleName => {
  42. entry[getOutputPath('admin', moduleName)] = [
  43. './client/src/utils/polyfills.js',
  44. `./client/src/entrypoints/${moduleName}.js`,
  45. ];
  46. });
  47. return {
  48. entry: entry,
  49. output: {
  50. path: path.resolve('.'),
  51. filename: '[name].js',
  52. publicPath: '/static/js/'
  53. },
  54. resolve: {
  55. extensions: ['.ts', '.tsx', '.js'],
  56. },
  57. externals: {
  58. jquery: 'jQuery',
  59. },
  60. module: {
  61. rules: [
  62. {
  63. test: /\.(js|ts)x?$/,
  64. loader: 'ts-loader',
  65. exclude: /node_modules/,
  66. },
  67. ].concat(Object.keys(exposedDependencies).map((name) => {
  68. const globalName = exposedDependencies[name];
  69. // Create expose-loader configs for each Wagtail dependency.
  70. return {
  71. test: require.resolve(name),
  72. use: [
  73. {
  74. loader: 'expose-loader',
  75. options: globalName,
  76. },
  77. ],
  78. };
  79. }))
  80. },
  81. optimization: {
  82. splitChunks: {
  83. cacheGroups: {
  84. vendor: {
  85. name: getOutputPath('admin', 'vendor'),
  86. chunks: 'initial',
  87. minChunks: 2,
  88. reuseExistingChunk: true,
  89. },
  90. },
  91. },
  92. },
  93. // See https://webpack.js.org/configuration/devtool/.
  94. devtool: 'source-map',
  95. // For development mode only.
  96. watchOptions: {
  97. poll: 1000,
  98. aggregateTimeout: 300,
  99. },
  100. // Disable performance hints – currently there are much more valuable
  101. // optimizations for us to do outside of Webpack
  102. performance: {
  103. hints: false
  104. },
  105. stats: {
  106. // Add chunk information (setting this to `false` allows for a less verbose output)
  107. chunks: false,
  108. // Add the hash of the compilation
  109. hash: false,
  110. // `webpack --colors` equivalent
  111. colors: true,
  112. // Add information about the reasons why modules are included
  113. reasons: false,
  114. // Add webpack version information
  115. version: false,
  116. // Set the maximum number of modules to be shown
  117. maxModules: 0,
  118. },
  119. // Some libraries import Node modules but don't use them in the browser.
  120. // Tell Webpack to provide empty mocks for them so importing them works.
  121. node: {
  122. fs: 'empty',
  123. net: 'empty',
  124. tls: 'empty',
  125. },
  126. };
  127. };