Most of the code in nuxt projects can now be written in modern ES6 syntax. Even more is going to be supported when 8 is next LTS (Such as async/await). However, there are parts currently are not fully ES6 compatible because are being required directly with node and thus depends on pure node functionalities. Also using babel-register to polyfill this gap may introduce many many inconsistencies and perf/stability issues which is not ideal. Current parts which can potentially leverage .mjs:
nuxt.config.jsThis article is useful for getting started with native esm. Currently, esm support can be enabled behind a flag so we would delay this feature for Nuxt until it gets stable enough.
PS: Any ideas, feedbacks, and contribution are welcome. our only limitation is that PRs should target v2 as this is almost breaking change in the entire ecosystem.
XREFs:
I think we can experiment most of the parts by using something like this to start Node.js process:
node --experimental-modules node_modules/.bin/nuxt --config ./nuxt.config.mjs
Again this article would be really helpful to get started :)
I'm experimenting with @std/esm to share code between client & server. How about wrapping all serverMiddleware code with this?
// serverMiddleware.js
const { Router } = require('express')
const router = Router()
const esm = require('@std/esm')(module, { esm: 'js', cjs: true })
router.use(esm('./some-api-module').router)
router.use(esm('./another-one').router)
module.exports = router
// some-api-module.js
import { Router } from 'express'
export const router = Router()
router.post('/...')
Shipped! (#1935)
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
I'm experimenting with
@std/esmto share code between client & server. How about wrapping all serverMiddleware code with this?