Node.js & module system
Node.js v10.9.0 Documentation
https://nodejs.org/api/modules.html#modules_modules
https://nodejs.org/api/modules.html#modules_the_module_wrapper
https://nodejs.org/api/modules.html#modules_exports_shortcut
CommonJS
CommonJS module system
http://nodejs.wikia.com/wiki/Modules
https://requirejs.org/docs/whyamd.html#commonjs
http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html
https://darrenderidder.github.io/talks/ModulePatterns/#/
https://addyosmani.com/writing-modular-js/
CJS
http://unscriptable.com/2011/09/30/amd-versus-cjs-whats-the-best-format/
http://www.commonjs.org/
Asynchronous Module Definition (AMD)
https://requirejs.org/docs/whyamd.html
https://github.com/amdjs/amdjs-api/wiki/AMD
UMD
UMD: Universal Module Definition
https://www.davidbcalhoun.com/2014/what-is-amd-commonjs-and-umd/
https://www.zhihu.com/question/20351507
node.js & exports & module.exports
node.js
-
Functions and objects
are added tothe root of a module
by specifying additional properties on the specialexports
object.
https://www.w3schools.com/nodejs/nodejs_modules.asp
https://www.sitepoint.com/understanding-module-exports-exports-node-js/
npx
https://*.com/questions/9679932/how-to-use-package-installed-locally-in-node-modules
nodejs & es6 & import & export
https://*.com/questions/31354559/using-node-js-require-vs-es6-import-export
Keep in mind that there is no JavaScript engine yet that natively supports
ES6 modules
. You said yourself that you are usingBabel
. Babel converts import and export declaration toCommonJS
(require/module.exports) by default anyway. So even if you use ES6 module syntax, you will be using CommonJSunder the hood
if you run the code in Node.
https://medium.com/the-node-js-collection/an-update-on-es6-modules-in-node-js-42c958b890c
ESM
https://hackernoon.com/node-js-tc-39-and-modules-a1118aecf95e
https://github.com/tc39/proposal-dynamic-import
webpack.config.js
https://github.com/carloluis/webpack-demo/tree/master/config
webpack dev & prod
https://github.com/carloluis/webpack-demo
https://github.com/carloluis/webpack-demo/blob/master/config/webpack.config.dev.js
https://github.com/carloluis/webpack-demo/blob/master/config/webpack.config.prod.js