Arerosuoghene Widestack Developer. I code for... The web (fullstack) Android iOS Windows Desktop and Windows Phone Find me on github, medium, twitter and facebook - @itswisdomagain
just combining HTML, CSS, Javascript and maybe jQuery/Ajax. Today… Everyone is talking about npm, yarn, webpack, babel. What in God’s good name are these really?
has evolved. Greatly! Ever heard of ES6? Typescript? Ever used them? 02 Browsers are slow to catch up with these magnificent evolutions. We shouldn’t let them slow us down! 03 So here’s the thing: Stop living in yesterday and start coding in 2018 . Get acquainted with various tools that can help.
their websites, don’t be lazy dhorr) Go to your project folder, open your terminal, and “initialize” the project using… npm init yarn init Find the name of the library you need and install the library from the command line using… npm install <package-name> --save yarn add <package-name>
Webpack increases overall performance of your websites by combining all your Javascript codes, from all the different RELATED files into a single file. This reduces page load time and when used appropriately, eliminates unnecessary Javascript codes not needed for each page.
now, you should have NPM installed on your PC, yeah? npm install webpack -g For each web page, create a corresponding Javascript file. Use the require keyword to include other needed Javascript files and libraries in this file. var jQuery = require(‘jQuery’) var myOtherJSFile = require(‘./path/to/file’) Do your thing, write your functions and declare your variables. Finally, BUNDLE using webpack. This will create a single JS file (the output file) by combining the codes from all the required files. webpack original-js-file.js output-js-file.js
thou can speakest modern English? Browsers are slow to adopt new features of the Javascript language. How do you write code in modern Javascript when the browsers are still behind? Babel has you covered! Just write, Babel will transpile your modern language to an older language so that those dull browsers can understand what ya saying...
scary, but it’ll turn out to be fun. Go, learn ES6. All the new and exciting features and master them by using them consistently. Okay, now install babel-core and her sisters - babel-preset-env (default babel configuration) and babel-loader (something to make babel work with webpack) npm install babel-core babel-preset-env babel-loader --save-dev Do your thing, write your functions and declare your variables using modern ES6 syntax and patterns. Babel + Webpack got you covered. As before, when done, bundle up... webpack original-js-file.js output-js-file.js
to keep external libraries organized Babel Be a ninja! Speak modern Javascript without fear. Works with Webpack --> Code in Action Include your bundled js file in your html file and see your code come to life Webpack Combine JS codes from different “modules” (libraries) and your own code into one single js file 01 02 03 04