* Remove `m.prop` + `m.withAttr` - For many uses, `m.withAttr` is *more* verbose than just directly using an event handler - If you're using it with a bound callback, you're literally wasting a single character in the human readable version (and you're *saving* them in the minified output). - It sometimes obscures your intent, if overused. - Functions are easier to compress than `m.withAttr`, resulting in slightly smaller bundles. - `m.withAttr` is overused anyways. - `m.prop` is basically useless without `m.withAttr`, and the API doesn't have the same benefits it had with 0.2.x. * Update changelog
67 lines
1.7 KiB
JavaScript
67 lines
1.7 KiB
JavaScript
"use strict"
|
|
|
|
/*
|
|
|
|
This script will create esm compatible scripts
|
|
from the already compiled versions of:
|
|
|
|
- mithril.js > mithril.mjs
|
|
- mithril.min.js > mithril.min.mjs
|
|
- /stream/stream.js > stream.mjs
|
|
|
|
*/
|
|
|
|
var fs = require("fs")
|
|
|
|
var namedExports = [
|
|
"m",
|
|
"trust",
|
|
"fragment",
|
|
"mount",
|
|
"route",
|
|
"render",
|
|
"redraw",
|
|
"request",
|
|
"jsonp",
|
|
"parseQueryString",
|
|
"buildQueryString",
|
|
"version",
|
|
"vnode",
|
|
"PromisePolyfill"
|
|
]
|
|
|
|
var mithril = fs.readFileSync("mithril.js", "utf8")
|
|
fs.writeFileSync("mithril.mjs",
|
|
mithril.slice(
|
|
mithril.indexOf("\"use strict\"") + 13,
|
|
mithril.lastIndexOf("if (typeof module")
|
|
)
|
|
+ "\nexport default m"
|
|
// The exports are declared with prefixed underscores to avoid overwriting previously
|
|
// declared variables with the same name
|
|
+ "\nvar " + namedExports.map(function(n) { return "_" + n + " = m." + n }).join(",")
|
|
+ "\nexport {" + namedExports.map(function(n) { return "_" + n + " as " + n }).join(",") + "}"
|
|
)
|
|
|
|
var mithrilMin = fs.readFileSync("mithril.min.js", "utf8")
|
|
var mName = mithrilMin.match(/window\.m=([a-z])}/)[1]
|
|
fs.writeFileSync("mithril.min.mjs",
|
|
mithrilMin.slice(
|
|
12,
|
|
mithrilMin.lastIndexOf("\"undefined\"!==typeof module")
|
|
)
|
|
+ "export default " + mName + ";"
|
|
// The exports are declared with prefixed underscores to avoid overwriting previously
|
|
// declared variables with the same name
|
|
+ "var " + namedExports.map(function(n) { return "_" + n + "=m." + n }).join(",") + ";"
|
|
+ "export {" + namedExports.map(function(n) { return "_" + n + " as " + n }).join(",") + "};"
|
|
)
|
|
|
|
var stream = fs.readFileSync("stream/stream.js", "utf8")
|
|
fs.writeFileSync("stream/stream.mjs",
|
|
stream.slice(
|
|
stream.indexOf("\"use strict\"") + 13,
|
|
stream.lastIndexOf("if (typeof module")
|
|
)
|
|
+ "\nexport default createStream"
|
|
)
|