ojet.config.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. Copyright (c) 2015, 2022, Oracle and/or its affiliates.
  3. Licensed under The Universal Permissive License (UPL), Version 1.0
  4. as shown at https://oss.oracle.com/licenses/upl/
  5. */
  6. const webpack = require("webpack");
  7. const merge = require("webpack-merge").merge;
  8. const package = require("./package.json");
  9. const developmentConfig = {
  10. plugins: [
  11. new webpack.DefinePlugin({
  12. API_PATH: JSON.stringify(process.env.API_PATH)
  13. })
  14. ],
  15. devServer: {
  16. https: process.env.HTTPS === "true",
  17. port: 8000,
  18. allowedHosts: [
  19. "localhost",
  20. package.config.host
  21. ],
  22. historyApiFallback: true,
  23. proxy: {
  24. "/api": {
  25. target: process.env.API_URL || "http://localhost:3000",
  26. pathRewrite: { "^/api": process.env.API_PATH || "" }
  27. },
  28. }
  29. }
  30. };
  31. module.exports = {
  32. /**
  33. *
  34. * @param {object} options.context - ojet build context which contains useful fields like
  35. * buildType
  36. * @param {object} options.config - Default webpack config generated by ojet. You can
  37. * add to it, remove from it or update it using webpack-merge which was
  38. * installed alongside webpack. If desired, you can create your own config
  39. * and return it which will override the default config
  40. * @returns {object|undefined}
  41. */
  42. webpack: ({ context, config }) => {
  43. if (context.buildType === "release") {
  44. // update config with release / production options
  45. } else {
  46. // update config with development options
  47. return merge(config, developmentConfig);
  48. }
  49. // only have to return if new config object was created but
  50. // since it doesn't matter always returning the config is good
  51. // practice
  52. return config;
  53. }
  54. };