简体   繁体   English

有可能将jQuery转换为Vanilla JS吗?

[英]Is it possible to transpile jQuery to Vanilla JS?

I use traceur / babel to transpile ES6 to ES5 but is it possible to use an gulp plugin to transpile jQuery to plain javascript? 我使用traceur / babel将ES6转换为ES5,但是可以使用gulp插件将jQuery转换为简单的javascript吗? Thanks for Your answers :) 谢谢你的回答:)

I think this is a totally valid question, I'm looking for this solution as i want to remove jQuery as a dependency from a few projects but don't want to have to go through old site scripts refactoring code. 我认为这是一个完全有效的问题,我正在寻找这个解决方案,因为我想从一些项目中删除jQuery作为依赖项,但不希望必须通过旧站点脚本重构代码。

Most of the general things we used jQuery for now have vanillaJS alternatives. 我们现在使用jQuery的大多数常规事物都有vanillaJS替代品。

There is no gulp plugin to transpile jQuery to javascript. 没有gulp插件可以将jQuery转换为javascript。 This is somewhat related to this question Is there an easy way to convert jquery code to javascript? 这与此问题有些相关是否有一种简单的方法将jquery代码转换为javascript? . What you would need to do is to find out what you are doing with jQuery and look up ways of doing it with vanilla javascript instead and then you would not need jQuery. 你需要做的是找出你正在使用jQuery做什么,并查找使用vanilla javascript的方法,然后你就不需要jQuery了。

You can open the jquery.js and look for the relevant functions you want to convert to native javascript. 您可以打开jquery.js并查找要转换为本机javascript的相关函数。

Copy it into a new helper.js, include it instead of jquery.js (or jquery.min.js) and use this functions. 将其复制到一个新的helper.js中,包含它而不是jquery.js(或jquery.min.js)并使用此函数。 Voila, native js-functions. Voila,原生js函数。

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

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