7
Wombat
3y

I want to use Babel or Typescript for the first time. Because as I read it is the way to go, when compressing JavaScript and make it browser compatible. If that's false, please correct me.

There's a question I've got about this. Right now I am using a PHP router file dealing with requests and selecting the right .js file and compresses it. So I can write like modular JavaScript functions and include them when needed.

My question is, what do I have to change in my setup to switch to the mentioned technologies?

Comments
  • 2
    @AlexDeLarge I actually just use Babel for node code. You don't need much when writing for node and Babel is enough I feel. All it does is transpiled ES6 imports/exports and remove flow types (while still keeping them in a separate file)

    But for frontend, Webpack for sure
  • 2
    (ran out of edit time)

    As for using Babel with dynamic js files. That's some next level voodoo man. Also, it won't scale.
    I use a dynamic js file in one of my projects (it's gets some parameters injected into it from the request) but I try to keep it as minimalistic as possible. Also, I don't transpile it since nothing in that project is transpiled 😄, so I can't help you here.
    To be honest I can see that being a ESLint/flow horror story if you tried to use those on a dynamic js file. They'd have no idea what to do since part of the file is in a templating language and makes 0 sense as javascript
  • 2
    @AlexDeLarge I bundle them in modular files for one reason. I tried to keep the output small for each page and so there were scripts I use only on one particular page and some I use on every page, like the script for the pages navigation. If that's a bad way to do this, I am all ears.
  • 1
    @AlexDeLarge @Froot also I glanced at Webpack and find out that it's pretty cool for development, because of his modular setting. Though I find it anoying tho explicitly define all files start end endpoint...
    I bought Prepros a while ago to work with Sass fluently. And it offers me also some preprocessing features for JavaScript, like Babel and Uglyfying. Do you also know Prepros? Can I achieve the same workflow with it alike Webpack?
  • 1
    @Divisionbyzero Sorry, never used it ☚ī¸
  • 1
    After learning more about Webpack there's a new question I have. How do I handle PHP in Webpack? I'm used to have controllers which load a view containing html, but all tutorials used Webpack to work with plain html files...
  • 1
    @Divisionbyzero Just take PHP out of the equation and it'll all be much much easier 😄
  • 1
    @Froot I don't get it 😅 I love PHP and want to frther use it.
  • 1
    @Divisionbyzero Don't. PHP is like meth. It feels good at first but in reality it's just dragging you down 😄

    (I had nothing useful to add to the conversation so I just rag on PHP like I always do 😄)
  • 2
    @Froot okay 😂 As a good methhead I will tell you I never again will use PHP. But you will know that I lied. 😅
  • 0
    Most would normally use php to serve the backend information in the form of json for their js frontends to consume and interact with it.

    So basically, you would create your js frontend and test the urls, transpile everything to (for example) an index.html with the correct scripr src connection and voila.
Add Comment