DEV Community

Discussion on: Getting started with MojiScript: FizzBuzz (part 1)

Collapse
 
jochemstoel profile image
Jochem Stoel

Joel, I would like to point out that a main.js does not prevent you from importing only the functions you need. It doesn't matter.

First of all, import statements will still work.

// this does not care about main.js in package.json
import pipe from 'mojiscript/core/pipe'

Secondly you can also require selectively only the stuff you need, exactly like import.

const { readFileSync, mkdir } = require('fs')
// or in your case
const { pipe, sleep, log } = require('mojiscript')
Thread Thread
 
joelnet profile image
JavaScript Joel

The design decision to create every function as it's own import was made to remove a footgun.

The footgun removed is the ability to import the entire library when you only need a few functions.

This way, the output bundle sir is only as big as the functions you import.

So MojiScript will have a microscopic footprint in your final output bundle because it is no longer possible to import the entire bundle.

Thread Thread
 
jochemstoel profile image
Jochem Stoel

I made a script called mojifier that converts your module into a single object with everything included / proper namespaces by iterating the directories/files.