简体   繁体   English

如何在快速工作区中转换简单的反应组件

[英]How to transpile simple react component in express workspace

I have a fairly simple question.我有一个相当简单的问题。 I was writing simple express page for company (basic table delete row button and form page) easyyyy我正在为公司写简单的快递页面(基本表格删除行按钮和表单页面)easyyyy

But I decided to spruce form page a little bit with ajax validation and dynamic fields.但我决定用 ajax 验证和动态字段稍微修饰一下表单页面。 Since I did few full react sites before i thought making this component would be easy.因为在我认为制作这个组件会很容易之前,我做了几个完整的反应站点。 And tbh making component is easy but babel and webpack is not.制作组件很容易,但 babel 和 webpack 不是。

is there any easy way to transpile jsx with imports to the web without configuring whole separate workspace?是否有任何简单的方法可以在不配置整个单独工作区的情况下将 jsx 导入 web?

If react for this overkill and jQuery fell out of grace is there any other suitable library?如果对这种过度杀伤做出反应并且 jQuery 失宠,还有其他合适的库吗?

Hope you can understand my broken English希望你能听懂我蹩脚的英语

yes react is powerful, you can add it and setup it like, you can create the component separately and load the script on your target page just make sure you place the mount point right是的,react 很强大,您可以添加它并设置它,您可以单独创建组件并将脚本加载到目标页面上,只需确保正确放置安装点

and you can use create react app with this as well你也可以用这个来创建反应应用程序

just build the project place the bundle js path on the same page and add the mount point and it should work smoothly只需构建项目将bundle js路径放在同一页面上并添加安装点,它应该可以顺利运行

<div id="mountPoint" ></div>

another way like the react does suggest here像反应这样的另一种方式确实在这里提出了建议

I did minimal configuration of webppack and babel.我做了 webppack 和 babel 的最小配置。 When it wasnt so bad still configuring two libraries for one small component with 2 dependencies seems ridiculous:P当它还没有那么糟糕时,仍然为一个具有 2 个依赖项的小组件配置两个库似乎很荒谬:P

My config maybe somebody finds it useful:我的配置也许有人觉得它有用:

webpack.config.js webpack.config.js

 const path = require('path'); module.exports = { mode: 'development', output: { filename: 'public/javascripts/dist.js' }, module: { rules: [ { test: /\.jsx$/, exclude: /(node_modules|bower_components)/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env', "@babel/preset-react"] } } } ] } };

babel.config.js babel.config.js

 module.exports = function (api) { api.cache(true); const presets = []; const plugins = ['@babel/plugin-proposal-class-properties']; return { presets, plugins }; }

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

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