r/javascript • • Sep 23 '19

You might not need a framework

https://medium.com/@pljeskavicica/you-might-not-need-a-framework-79444bda50d2
70 Upvotes

129 comments sorted by

View all comments

Show parent comments

6

u/fuzzball007 Sep 23 '19 edited Sep 23 '19

How does it go in terms of dropping it onto a page with limited build tools? My use case would be something simple like displaying cards based on an ajax request, along with dropdowns/selects for tags/categories and pagination.

I've only learned React's basics, so for most of my projects which aren't large webapps I've been turned off from webpack's build process. Typically use gulp for all my stuff, how'd it go in a situation like this? Sounds appealing so far.

Edit: I'm usually building in PHP (WordPress) hence dropping onto a single page or two where's there's actual functionality to build. The stuff I've done using jQuery got messy quite quickly, even with using a fake state to store data before writing to the DOM

5

u/lifeeraser Sep 23 '19

I use Preact without build tools. (P)react is fully capable of running in a browser by itself with vanilla JS code. To use JSX, though, you need a transpiler, fall back to Hyperscript, or use something like htm.

1

u/volimsir Sep 24 '19

Without build tools? Do you mind sharing an example of your setup? I'm genuinely interested.

No IE support for htm though :(

2

u/lifeeraser Sep 24 '19

Sure. Here's how I did it:

  1. npm install preact

  2. Embed a <script> tag pointing to ./node_modules/preact/dist/preact.umd.js in my app (I use UMD). Now, I can access preact as a global variable.

  3. Alternatively, use ./node_modules/preact/dist/preact.module.js if you prefer ES6 import.

If you want, preact/compat and preact/hooks are available as separate JS files in ./node_modules/preact/compat/dist/ and ./node_modules/preact/hooks/dist/.