How should we use this as a helper for transitioning to mjs? Such as:
package.json:
{
name: 'some-module',
main: 'main.js',
module: 'main.mjs'
}
main.js:
require = require("@std/esm")(module)
module.exports = require("./main.mjs").default
main.mjs:
export default // ... real module code.
So that the majority in npm would be written in mjs at last.
Since module field in package.json is still a proposal, is there another recommended way for doing this?
Hi @amio!
The module field doesn't really factor into things at the moment.
The suggested usage for the current released versions is to use a main cjs file to bootstrap loading esm files. If the module field doesn't become a thing when 2020 rolls around, and you'd like to drop @std/esm, then you'd simply swap the main field to main.mjs.
Most helpful comment
Hi @amio!
The
modulefield doesn't really factor into things at the moment.The suggested usage for the current released versions is to use a main cjs file to bootstrap loading esm files. If the
modulefield doesn't become a thing when 2020 rolls around, and you'd like to drop@std/esm, then you'd simply swap themainfield tomain.mjs.