webpack.base.config.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. var _ = require('lodash');
  2. var path = require('path');
  3. var glob = require('glob').sync;
  4. var webpack = require('webpack');
  5. var COMMON_PATH = './wagtail/wagtailadmin/static/wagtailadmin/js/common.js';
  6. function appName(filename) {
  7. return _(filename)
  8. .split(path.sep)
  9. .get(2);
  10. }
  11. function entryPoint(filename) {
  12. var name = appName(filename);
  13. var entryName = path.basename(filename, '.entry.js');
  14. var outputPath = path.join('wagtail', name, 'static', name, 'js', entryName);
  15. return [outputPath, filename];
  16. }
  17. function entryPoints(paths) {
  18. return _(glob(paths))
  19. .map(entryPoint)
  20. .fromPairs()
  21. .value();
  22. }
  23. module.exports = function exports() {
  24. var CLIENT_DIR = path.resolve(__dirname, 'client', 'src');
  25. return {
  26. entry: entryPoints('./wagtail/**/static_src/**/app/*.entry.js'),
  27. resolve: {
  28. alias: {
  29. components: path.resolve(CLIENT_DIR, 'components')
  30. }
  31. },
  32. output: {
  33. path: './',
  34. filename: '[name].js',
  35. publicPath: '/static/js/'
  36. },
  37. plugins: [
  38. new webpack.ProvidePlugin({
  39. fetch: 'imports?this=>global!exports?global.fetch!whatwg-fetch'
  40. }),
  41. new webpack.optimize.CommonsChunkPlugin('common', COMMON_PATH, Infinity)
  42. ],
  43. devtool: '#inline-source-map',
  44. module: {
  45. loaders: [
  46. {
  47. test: /\.js$/,
  48. loader: 'babel',
  49. exclude: /node_modules/,
  50. include: [
  51. CLIENT_DIR,
  52. path.resolve(__dirname, 'wagtail')
  53. ]
  54. },
  55. {
  56. test: /\.jsx$/,
  57. loader: 'babel',
  58. exclude: /node_modules/,
  59. include: [
  60. CLIENT_DIR,
  61. path.resolve(__dirname, 'wagtail')
  62. ]
  63. }
  64. ]
  65. }
  66. };
  67. };