This is a CFP for ReactiveConf open call for lightning talks. If you'd like to see this talk become a reality, please ⭐️ star this gist. #ReactiveConf
import babel from 'rollup-plugin-babel' | |
import commonjs from 'rollup-plugin-commonjs' | |
import postcss from 'rollup-plugin-postcss' | |
import resolve from 'rollup-plugin-node-resolve' | |
import pkg from './package.json' | |
export default { | |
input: 'src/index.js', | |
output: [ |
// File log.js | |
function log(){ | |
console.log('Example of CJS module system'); | |
} | |
// expose log to other modules | |
module.exports = { log } | |
// File index.js | |
var logModule = require('./log'); | |
logModule.log(); |
// File log.js | |
define(['logModule'], function(){ | |
// export (expose) foo for other modules | |
return { | |
log: function(){ | |
console.log('Example of AMD module system'); | |
} | |
}; | |
}); |
// File log.js | |
(function (global, factory) { | |
if (typeof define === "function" && define.amd) { | |
define(["exports"], factory); | |
} else if (typeof exports !== "undefined") { | |
factory(exports); | |
} else { | |
var mod = { | |
exports: {} | |
}; |
// File log.js | |
const log = () => { | |
console.log('Example of ES module system'); | |
} | |
export default log | |
// File index.js | |
import log from "./log" | |
log(); |
// File shakebake.js | |
const shake = () => console.log('shake'); | |
const bake = () => console.log('bake'); | |
//can be tree shaken as we export as es modules | |
export { shake, bake }; | |
// File index.js | |
import { shake } from './shakebake.js' | |
// only shake is included in the output |
Seen a few tweets on this. I want to dispel some FUD.
Node is probably going to introduce a new file extension for JavaScript modules, .mjs
. The reasons for this are long and perilous, and trying to summarize the discussion that led to it is maddening. The short version is that ES6 modules have different semantics from existing scripts, and need to be executed differently. In browsers, this is done with <script type="module">
. In Node, this will be done by analyzing the file extension of the imported file.
I'll be honest: I don't love this solution! I was rooting for the TC39 counter-proposal. But I also understand the solution that the Node developers chose, and why they chose it.
The new file extension is a good enough solution. You can read the [draft spec](https://github.com/nodejs/node-eps/