CommonJS to ES6 module
Change the purescript output file to ES6 modules, then we can benefit from ES6 tree shaking.
Example
Control.Alt/index.js:
"use strict";
var Data_Functor = require("../Data.Functor");
var Data_Semigroup = require("../Data.Semigroup");
var Alt = function (Functor0, alt) {
this.Functor0 = Functor0;
this.alt = alt;
};
var altArray = new Alt(function () {
return Data_Functor.functorArray;
}, Data_Semigroup.append(Data_Semigroup.semigroupArray));
var alt = function (dict) {
return dict.alt;
};
module.exports = {
Alt: Alt,
alt: alt,
altArray: altArray
};
Out goes ES6 js:
'use strict';
import { Data_Functor_functorArray } from '../Data.Functor';
import {
Data_Semigroup_append,
Data_Semigroup_semigroupArray
} from '../Data.Semigroup';
var Alt = function (Functor0, alt) {
this.Functor0 = Functor0;
this.alt = alt;
};
var altArray = new Alt(function () {
return Data_Functor_functorArray;
}, Data_Semigroup_append(Data_Semigroup_semigroupArray));
var alt = function (dict) {
return dict.alt;
};
export var Control_Alt_Alt = Alt;
export var Control_Alt_alt = alt;
export var Control_Alt_altArray = altArray;
Install
yarn add cjstoes --dev
Usage
const cjstoes = require('cjstoes')
const fse = require('fs-extra')
const glob = require('glob')
const { readFileSync, writeFileSync } = require('fs')
fse.copySync(`${process.cwd()}/output`, `${process.cwd()}/outputES6`)
glob.sync(`${process.cwd()}/outputES6/**/*.js`).forEach(file => {
let f = readFileSync(file, 'utf8')
let nf = cjstoes(f, file)
writeFileSync(file, nf)
})