Reactjs React CRA构建时间变量问题-多条目解决方案
我正在尝试使用react和CreateReact应用程序,根据使用动态导入的环境变量选择构建目标。以下是我试图实现的目标: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
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