webpack.config.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. const fs = require('fs')
  2. const path = require('path')
  3. const MODULES_PATH = path.join(__dirname, '/modules')
  4. // Generate a hash of entry points, including modules
  5. const entryPoints = {}
  6. if (fs.existsSync(MODULES_PATH)) {
  7. fs.readdirSync(MODULES_PATH).reduce((acc, module) => {
  8. const entryPath = path.join(MODULES_PATH, module, '/public/es/index.js')
  9. if (fs.existsSync(entryPath)) {
  10. acc[module] = entryPath
  11. }
  12. return acc
  13. }, entryPoints)
  14. }
  15. // If no entry points are found, silently exit
  16. if (!Object.keys(entryPoints).length) {
  17. console.warn('No entry points found, exiting')
  18. process.exit(0)
  19. }
  20. module.exports = {
  21. // Defines the "entry point(s)" for the application - i.e. the file which
  22. // bootstraps the application
  23. entry: entryPoints,
  24. // Define where and how the bundle will be output to disk
  25. // Note: webpack-dev-server does not write the bundle to disk, instead it is
  26. // kept in memory for speed
  27. output: {
  28. path: path.join(__dirname, '/public/js/es'),
  29. filename: '[name].js',
  30. // Output as UMD bundle (allows main JS to import with CJS, AMD or global
  31. // style code bundles
  32. libraryTarget: 'umd',
  33. // Name the exported variable from output bundle
  34. library: ['Frontend', '[name]']
  35. },
  36. // Define how file types are handled by webpack
  37. module: {
  38. rules: [{
  39. // Pass application JS files through babel-loader, compiling to ES5
  40. test: /\.js$/,
  41. // Only compile application files (dependencies are in ES5 already)
  42. exclude: /node_modules/,
  43. use: [{
  44. loader: 'babel-loader',
  45. options: {
  46. presets: [
  47. 'react',
  48. ['env', { modules: false }]
  49. ],
  50. // Configure babel-loader to cache compiled output so that subsequent
  51. // compile runs are much faster
  52. cacheDirectory: true
  53. }
  54. }]
  55. }]
  56. },
  57. // TODO
  58. // plugins: {}
  59. }