webpack.config.js 975 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. const commonConfig = require("./build-utils/webpack.common");
  2. const webpackMerge = require("webpack-merge");
  3. const defaultEnv = { env: "prod" };
  4. /**
  5. *
  6. * @param {string|Array} addonsArg
  7. * @return {unknown[]}
  8. */
  9. const addons = addonsArg => {
  10. // Normalize array of addons (flatten).
  11. let addons = [].concat
  12. .apply([], [addonsArg])
  13. // If addons is undefined, filter it out.
  14. .filter(Boolean);
  15. return addons.map(addonName =>
  16. require(`./build-utils/addons/webpack.${addonName}.js`)
  17. );
  18. };
  19. // Export a function returning config instead of a static config.
  20. // The purpose is to allow use of the environment.
  21. module.exports = (env = defaultEnv) => {
  22. console.log(env);
  23. const envConfig = require(`./build-utils/webpack.${env.env}`);
  24. // The rightmost overwrites (merges into) its left sibling.
  25. const mergedConfig = webpackMerge(
  26. commonConfig,
  27. envConfig,
  28. ...addons(env.addons)
  29. );
  30. console.log(mergedConfig);
  31. return mergedConfig;
  32. };