Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React CRA构建时间变量问题-多条目解决方案_Reactjs_Create React App - Fatal编程技术网

Reactjs React CRA构建时间变量问题-多条目解决方案

Reactjs React CRA构建时间变量问题-多条目解决方案,reactjs,create-react-app,Reactjs,Create React App,我正在尝试使用react和CreateReact应用程序,根据使用动态导入的环境变量选择构建目标。以下是我试图实现的目标: const BUILD_TARGETS : ITarget[] = [ { name: "app", path: "./modules/app/Index", }, { name: "admin", path: "./modules/admin/Index&qu

我正在尝试使用react和CreateReact应用程序,根据使用动态导入的环境变量选择构建目标。以下是我试图实现的目标:

const BUILD_TARGETS : ITarget[] = [
  {
    name: "app",
    path: "./modules/app/Index",
  },
  {
    name: "admin",
    path: "./modules/admin/Index",
  },
];


// Determine which entry point to import
const target = BUILD_TARGETS.find(c=>process.env.REACT_APP_BUILD_TARGET === c.name) as ITarget;

//Import the entry point and render it's default export
import(`${target.path}`).then(({ default: BuildTarget }) =>
  ReactDOM.render(
   
    <>
    <BuildTarget />
  
    </>
      ,
    document.getElementById("root")
  )
);
build.ps1

$module=$args[0]
$script=$args[1]
Copy-Item $module -Destination "src/index.tsx"
npm run-script $script
"build-app": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./build.ps1 src\\app.index.tsx build",
"build-admin": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./build.ps1 src\\admin.index.tsx build",
"start-app": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./build.ps1 src\\app.index.tsx start",
"start-admin": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./build.ps1 src\\admin.index.tsx start"
$module=$args[0]
$script=$args[1]
Copy-Item $module -Destination "src/index.tsx"
npm run-script $script