Search This Blog

Monday, January 22, 2018

No-pain JavaScript project

Starting a JavaScript project can be so much work nowadays. Back in the day, you could open Notepad, load jQuery, and have something ready within the hour. Now frameworks with complicated build steps (transpile, package modules) and lots of files are expected.

I was listening (late) to StackOverflow podcast #120, where they discussed Glitch.com, a platform that sets a low bar for beginning a JS project. It also has a friendly, helpful community. All in all, it reminded me a lot of Scratch, where i learned to program.

Anyways, for an app i'm working on (React Native), i needed a simple web page to run a certain tool. This would need a JSON file from the app.

I could do it in React, compiled with Babel and Webpack, but that would seriously be overkill.

I decided to go old-school-ish and use a simple HTML file with jQuery. I can load the JSON (actually a JS module that exports an object) directly because Chrome now supports ES6 modules. The tool is internal-only, so lack of support elsewhere doesn't matter.

At first it felt kind of weird, using jQuery with ES6. Even using ES6 with no transpiling was a bit odd at first. I tried using an arrow function in a jQuery callback before remembering that i actually need a regular function that can receive this. But after, it was great! I could write simple, modern code, that i ran using only a static file server.

It works, and i'd gladly do it again when needed.

2 comments: