base.config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. // Generates a path to an entry file to be compiled by Webpack.
  4. const getEntryPath = (app, filename) => path.resolve('wagtail', app, 'static_src', `wagtail${app}`, 'app', filename);
  5. // Generates a path to the output bundle to be loaded in the browser.
  6. const getOutputPath = (app, filename) => path.join('wagtail', app, 'static', `wagtail${app}`, 'js', filename);
  7. // Mapping from package name to exposed global variable.
  8. const exposedDependencies = {
  9. 'focus-trap-react': 'FocusTrapReact',
  10. 'react': 'React',
  11. 'react-dom': 'ReactDOM',
  12. 'react-transition-group/CSSTransitionGroup': 'CSSTransitionGroup',
  13. 'draft-js': 'DraftJS',
  14. };
  15. module.exports = function exports() {
  16. const entry = {
  17. // Create a vendor chunk that will contain polyfills, and all third-party dependencies.
  18. vendor: [
  19. './client/src/utils/polyfills.js',
  20. ],
  21. };
  22. entry[getOutputPath('admin', 'wagtailadmin')] = getEntryPath('admin', 'wagtailadmin.entry.js');
  23. entry[getOutputPath('admin', 'draftail')] = getEntryPath('admin', 'draftail.entry.js');
  24. return {
  25. entry: entry,
  26. output: {
  27. path: path.resolve('.'),
  28. filename: '[name].js',
  29. publicPath: '/static/js/'
  30. },
  31. plugins: [
  32. new webpack.optimize.CommonsChunkPlugin({
  33. name: 'vendor',
  34. filename: getOutputPath('admin', '[name].js'),
  35. minChunks: 2,
  36. }),
  37. ],
  38. resolve: {
  39. alias: {
  40. 'wagtail-client': path.resolve('.', 'client'),
  41. },
  42. },
  43. module: {
  44. rules: [
  45. {
  46. test: /\.js$/,
  47. loader: 'babel-loader',
  48. exclude: /node_modules/,
  49. },
  50. ].concat(Object.keys(exposedDependencies).map((name) => {
  51. const globalName = exposedDependencies[name];
  52. // Create expose-loader configs for each Wagtail dependency.
  53. return {
  54. test: require.resolve(name),
  55. use: [
  56. {
  57. loader: 'expose-loader',
  58. options: globalName,
  59. },
  60. ],
  61. };
  62. }))
  63. },
  64. // See https://webpack.js.org/configuration/devtool/.
  65. devtool: 'source-map',
  66. stats: {
  67. // Add chunk information (setting this to `false` allows for a less verbose output)
  68. chunks: false,
  69. // Add the hash of the compilation
  70. hash: false,
  71. // `webpack --colors` equivalent
  72. colors: true,
  73. // Add information about the reasons why modules are included
  74. reasons: false,
  75. // Add webpack version information
  76. version: false,
  77. // Set the maximum number of modules to be shown
  78. maxModules: 0,
  79. },
  80. // Some libraries import Node modules but don't use them in the browser.
  81. // Tell Webpack to provide empty mocks for them so importing them works.
  82. node: {
  83. fs: 'empty',
  84. net: 'empty',
  85. tls: 'empty',
  86. },
  87. };
  88. };