base.config.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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', 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', app, 'js', filename);
  7. const isVendorModule = (module) => {
  8. const res = module.resource;
  9. return res && res.indexOf('node_modules') >= 0 && res.match(/\.js$/);
  10. };
  11. module.exports = function exports() {
  12. const entry = {
  13. // Create a vendor chunk that will contain polyfills, and all third-party dependencies.
  14. vendor: ['whatwg-fetch', 'babel-polyfill'],
  15. };
  16. entry[getOutputPath('wagtailadmin', 'wagtailadmin')] = getEntryPath('wagtailadmin', 'wagtailadmin.entry.js');
  17. return {
  18. entry: entry,
  19. output: {
  20. path: '.',
  21. filename: '[name].js',
  22. publicPath: '/static/js/'
  23. },
  24. plugins: [
  25. new webpack.optimize.CommonsChunkPlugin({
  26. name: 'vendor',
  27. filename: getOutputPath('wagtailadmin', '[name].js'),
  28. minChunks: isVendorModule,
  29. }),
  30. ],
  31. resolve: {
  32. alias: {
  33. 'wagtail-client': path.resolve('.', 'client'),
  34. },
  35. },
  36. module: {
  37. loaders: [
  38. {
  39. test: /\.js$/,
  40. loader: 'babel'
  41. },
  42. ]
  43. },
  44. stats: {
  45. // Add chunk information (setting this to `false` allows for a less verbose output)
  46. chunks: false,
  47. // Add the hash of the compilation
  48. hash: false,
  49. // `webpack --colors` equivalent
  50. colors: true,
  51. // Add information about the reasons why modules are included
  52. reasons: false,
  53. // Add webpack version information
  54. version: false,
  55. },
  56. };
  57. };