v1.0.0
With the release of unbuild v3, the EOL status of Nuxt 2, and looking forward to Nuxt 4, we're taking the opportunity to release v1 of @nuxt/module-builder
, with a range of breaking changes.
⚠️ Breaking Changes
-
Upgrade to unbuild v3 (#447)
This major upgrade brings significant changes to the build proces but should be significantly better. -
Removal of Node10 module resolution and CommonJS output (#448)
As Nuxt 2 has reached EOL, we no longer generate CJS by default, and we have also removed the 'CJS bridge' feature that polyfilled__filename
and__dirname
. -
Type errors. The module builder will now error if there are type errors when generating your
runtime/*
files. (Previously warnings were logged but your build would have succeeded.) Errors you receive aren't caused by the upgrade, but you might need to correct any issues before your module will build again.
🚧 Migration Guide
Replacing __filename
and __dirname
We no longer polyfill these CommonJS variables. Instead, use the createResolver
utility from @nuxt/kit
:
import { createResolver } from '@nuxt/kit'
// Instead of __dirname and __filename
const resolver= createResolver(import.meta.url)
const runtimeDir = resolver.resolve('./runtime')
Module Resolution Changes
We no longer officially support Node10 module resolution, meaning you should remove the types
/type
field from your package.json
. If you need to maintain compatibility with older Node.js versions or systems expecting CommonJS, you can use the typesVersions
field in your package.json
.
This field allows typing subpath exports (like my-module/utils
) even with older moduleResolution
settings. Regardless, we recommend all Nuxt users to use Bundler
module resolution.
{
"typesVersions": {
"*": {
".": [
"dist/index.d.mts"
],
"some-subpath": [
"dist/some-subpath.d.mts"
]
}
}
}
ESM-only Output
We no longer generate CommonJS (.cjs
) output files by default, as this was primarily needed for Nuxt 2 compatibility. You should:
- Set
"type": "module"
in your package.json - Update any mentions of
.cjs
files in yourpackage.json
For example:
+ "type": "module",
"exports": {
".": {
- "types": "./dist/types.d.ts",
+ "types": "./dist/types.d.mts",
"import": "./dist/module.mjs",
- "require": "./dist/module.cjs"
},
- "./utils": {
- "types": "./dist/utils.d.mts",
- "import": "./dist/utils.mjs",
- "require": "./dist/utils.cjs"
+ "./utils": "./dist/utils.mjs"
},
- "main": "./dist/module.cjs",
+ "main": "./dist/module.mjs",
- "types": "./dist/module.d.ts",
+ "typesVersions": {
+ "*": {
+ ".": [
+ "./dist/types.d.mts"
+ ],
+ "utils": [
+ "./dist/utils.d.mts"
+ ]
+ }
+ },
"files": [
- "utils.d.ts"
"dist"
],
Configuring unbuild
You can still customize the build process by extending the unbuild configuration in your buildOptions
.
To customize/extend the unbuild configuration you can add a build.config.ts
in the root of your project:
import { defineBuildConfig } from 'unbuild'
export default defineBuildConfig({
// set additional configuration or customize using hooks
rollupOptions: {
// for example, if you wish to continue to generate `.cjs` output
emitCJS: true
}
})
✨ Changelog
🚀 Enhancements
⚠️ Upgrade to unbuild v3 (#447)⚠️ Remove support for node10 resolution + cjs (#448)- build: Ignore test + story files in runtime/ directory (#480)
- Add support for type exports in module re-exports (#563)
🩹 Fixes
- Mark nuxi as optional peerDep (29a42ae)
- Drop @nuxt/kit peer dependency & remove optionality for nuxi (5936063)
- build: Handle windows path names (#399)
- build: Apply resolved tsconfig to dts (#462)
- Handle node10 resolution + add attw test (7309198)
- Update warnings (6291cbe)
- Support more than one line of type exports (0c0020f)
- Split re-exports across multiple lines (7154a89)
- Support star exports (8966047)
📖 Documentation
- Update example build script (#359)
- Update link to downloads count badge (9804e9e)
- Describe configuring unbuild (#440)
🏡 Chore
- Use tinyexec in test suite (7ff8ef1)
- Fix links (2e57eb2)
- Pin typescript until issue with vue-tsc is resolved (994135d)
- Bump vue-tsc (e8cb0ef)
- Bump nuxi version (5b1f00e)
- Add publint to dev dependencies (7281ae3)
- Set node versions and enable knip (1a17c0c)
- Stub module before stubbing playground (b3a513b)
- Run install command to relink binaries (932729e)
- Update command and add builder to workspace (#482)
- Add type assertion (14d7788)
- Add more type-safe solution + fallback (66d4231)
- Add pkg.pr.new for nightly/pr builds (#573)
- Bump to latest mkdist and add vue-sfc-transformer (673152a)
- Update knip config (c9a28a0)
- Bump vue-sfc-transformer version (3cd9cd4)
- release: V1.0.0 (b0655d3)
✅ Tests
- Await file snapshot assertions (16930b4)
- Assert current vue snapshot behaviour (#444)
- Update snapshots (847d150)
🤖 CI
- Don't run publint on windows (330f412)
- Prepare environment in lint step (5f0f88f)
- Force latest corepack (9d74ce4)
⚠️ Breaking Changes
❤️ Contributors
- Daniel Roe (@danielroe)
- Dev (@productdevbook)
- Bobbie Goede (@BobbieGoede)