webpack.config.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. module.exports = {
  16. // Defines the "entry point(s)" for the application - i.e. the file which
  17. // bootstraps the application
  18. entry: entryPoints,
  19. // Define where and how the bundle will be output to disk
  20. // Note: webpack-dev-server does not write the bundle to disk, instead it is
  21. // kept in memory for speed
  22. output: {
  23. path: path.join(__dirname, '/public/js/es'),
  24. filename: '[name].js',
  25. // Output as UMD bundle (allows main JS to import with CJS, AMD or global
  26. // style code bundles
  27. libraryTarget: 'umd',
  28. // Name the exported variable from output bundle
  29. library: ['Frontend', '[name]']
  30. },
  31. // Define how file types are handled by webpack
  32. module: {
  33. rules: [{
  34. // Pass application JS files through babel-loader, compiling to ES5
  35. test: /\.js$/,
  36. // Only compile application files (dependencies are in ES5 already)
  37. exclude: /node_modules/,
  38. use: [{
  39. loader: 'babel-loader',
  40. options: {
  41. presets: [
  42. ['env', { modules: false }]
  43. ],
  44. // Configure babel-loader to cache compiled output so that subsequent
  45. // compile runs are much faster
  46. cacheDirectory: true
  47. }
  48. }]
  49. }]
  50. },
  51. // TODO
  52. // plugins: {}
  53. }