Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

feat: add devServer config entry for users #263

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

FrankKai
Copy link

@FrankKai FrankKai commented Apr 1, 2022

What does this pull request introduce? Please describe
feat: add devServer config entry for users

How did you verify that your changes work as expected? Please describe
Make local dev happy.

Solve this problem #218

Example

const { webpackConfig } = require('direflow-scripts');
const devServerProxy = require("./config/devServerProxy");

/**
 * Webpack configuration for Direflow Component
 * Additional webpack plugins / overrides can be provided here
 */
module.exports = {
  webpack: (config, env) => {
    return {
      ...webpackConfig(config, env),
      // Add your own webpack config here (optional)
    };
  },
  devServer: function (configFunction) {
    return function (proxy, allowedHost) {
      // Config your own devServer proxy in ./config/devServerProxy.js
      proxy = devServerProxy();

      const config = configFunction(proxy, allowedHost);
      return config;
    };
  },
};
/**
 * Use the mock proxy 
 * 
 * If isMock is true, mockTarget is valid, target is invalid.
 */
 const isMock = false;

/**
 * Change the proxy env 
 * 'test', 'dev', etc. target is valid, mockTarget is invalid.
 */

const env = "dev"; 


/**
 * This is the default devServer proxy config, you can use it in proxyCustomConfig or not.
 */
const DEFAULT_PROXY_CONFIG = {
  secure: false,
  changeOrigin: true,
};

/**
 * Config your proxy api here.
 */
const config = {
  "/api": {
    target: {
      dev: "https://api.dev.com/",
      test: "https://api.test.com/",
    },
    mockTarget: "https://api.mock.com/",
    proxyCustomConfig: { ...DEFAULT_PROXY_CONFIG },
  },
  "/apiAnother": {
    target: {
      dev: "https://api.another.dev.com/",
      test: "https://api.another.test.com/",
    },
    mockTarget: "https://api.another.mock.com/",
    proxyCustomConfig: { ...DEFAULT_PROXY_CONFIG },
  },
};

Screenshots
If applicable, add screenshots to demonstrate your changes.

Version
3.5.4

Did you remember to update the version of Direflow as explained here:
https://github.com/Silind-Software/direflow/blob/master/CONTRIBUTING.md#version

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant