I don't understand what actual concrete benefit there is to using .mjs on client-side JavaScript modules. It seems to only cause problems with tools that .js completely avoids. What's the specific upside?
Tools are increasingly adopting .mjs as a signal that the source file is a module instead of a classic script, reducing the need for additional configuration in build systems.
-
-
With .mjs for modules, the mental model is: // Decide which extension to use: extension = isModule ? '.mjs' : '.js' // Figure out if a given file is a module: isModule = extension === '.mjs'
-
With .js for client-side modules, the mental model becomes: // Decide which extension to use: extension = (isBrowserOnlyCode || !isModule) ? '.js' : '.mjs' // Is the given file a module: isModule = extension === '.mjs' || (isBrowserOnlyCode && lookWhereAndHowFileGetsLoaded);
- 2 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.