简体   繁体   English

尝试在生产中的反应应用程序中添加自定义 HTML 和 JS 代码

[英]Trying to add the custom HTML and JS code in react application in production

As in many SaaS application we provide admins to add custom HTML, CSS and JS directly from any backend form.与许多 SaaS 应用程序一样,我们提供管理员直接从任何后端表单添加自定义 HTML、CSS 和 JS。 It works perfectly in applications built without any JS framework like react or vue.它在没有任何 JS 框架(如 react 或 vue)的应用程序中完美运行。

I want to do the same with react application.我想对反应应用程序做同样的事情。 The solution that I am thinking can be-我正在考虑的解决方案可以是-

  1. Add the custom code to bundle.js after compiling.编译后将自定义代码添加到 bundle.js 中。 We can use gulp or webpack to compile the code or something to apply those changes to the production build of react application.我们可以使用 gulp 或 webpack 来编译代码或其他东西,以将这些更改应用于 react 应用程序的生产构建。
  2. Is it possible to add the code in the public/index.js directly when the code is in production代码在生产时是否可以直接在public/index.js中添加代码

I may be wrong.我可能错了。 Please suggest me any possible way to make things in production react application.请向我建议任何可能的方法来使生产反应应用程序中的东西。

I really can't say anything about q1 .我真的无话可说q1 But for q2 it is not a good option to add code in index.js file even if it runs locally.但是对于q2 ,即使它在本地运行,在index.js文件中添加代码也不是一个好的选择。 It is not a good practice to write all your code in index.js or App.js .index.jsApp.js中编写所有代码并不是一个好习惯。 Trying to make components and write cleaner code is the beauty of React .尝试制作组件并编写更简洁的代码是React的美妙之处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM