Internet
Seminar

Spring 2019
course
site

JavaScript Module

Just like another high-level programming language, JavaScript has modular system to let users combine, seperate multiple files. However, module concept in JavaScript is relatively new. This Google developer page explains history, features, and how you use them pretty well. export and import are the keywords to start moduling your files. You may import and export variables, functions, and classes.

Bundling

Most of JavaScript new features problems are browser support and modules is one of them. Since, it's not a built-in feature in plain JavaScript language, some old browsers do not support this concept. Developers solve this problem by setting up a routine where their multiple files are combined before they attach it to HTML. Browserify is one of methods that people use. The concept is similar to how GCC combines multiple C files and link them into one giant file. One advantage is you only need to carry one giant file and you are good. You do not have to worry about dependencies or missing files. However, if you do not carefully choose what to include in the file, sometimes the file might go big unnecessarily.

Transpiling

Another part of bundling is transpiling. It is due to browser support problem that may occur. One of the famous one is Babel. So, after you bundle your code into one giant file, babel will transpile your code that might contain future prototype feature of JavaScript into old plain JavaScript that most of browsers support.

Example

node --experimental-modules module1.mjs

>(node:5645) ExperimentalWarning: The ESM module loader is experimental.
>You request for Happines but I am module 2
>You request for alternate module but I am module 2 and you access this from module 3.
>I am module 4

https://cs.marlboro.college /cours /spring2019 /internet /www /fazah /module /module
last modified Wed July 3 2024 7:45 am

attachments [paper clip]

  last modified size
TXT module1.mjs Wed Jul 03 2024 07:45 am 194B
TXT module2.mjs Wed Jul 03 2024 07:45 am 113B
TXT tmp/ Wed Jul 03 2024 07:45 am