Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/prefetch-improve…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
danielroe committed Oct 17, 2022
2 parents bb51f8f + 573ed5c commit 4154eee
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 92 deletions.
2 changes: 1 addition & 1 deletion docs/content/1.getting-started/5.routing.md
Expand Up @@ -134,7 +134,7 @@ definePageMeta({
validate: async (route) => {
const nuxtApp = useNuxtApp()
// Check if the id is made up of digits
return /^\d+$/.test(params.id)
return /^\d+$/.test(route.params.id)
}
})
</script>
Expand Down
16 changes: 16 additions & 0 deletions docs/content/3.api/5.commands/build-module.md
@@ -0,0 +1,16 @@
# `nuxi build-module`

```{bash}
npx nuxi build-module [--stub] [rootDir]
```

The `build-module` command runs `@nuxt/module-builder` to generate `dist` directory within your `rootDir` that contains the full build for your **nuxt-module**.

Option | Default | Description
-------------------------|-----------------|------------------
`rootDir` | `.` | The root directory of the module to bundle.
`--stub` | `false` | Stub out your module for development using [jiti](https://github.com/unjs/jiti#jiti). (**note:** This is mainly for development purposes.)

::alert
This command is only available when you are using `@nuxt/module-builder` to build your module. Please see [this readme](https://github.com/nuxt/module-builder#-nuxt-module-builder) for more information.
::
33 changes: 33 additions & 0 deletions packages/nuxi/src/commands/build-module.ts
@@ -0,0 +1,33 @@
import { execa } from 'execa'
import consola from 'consola'
import { resolve } from 'pathe'
import { tryResolveModule } from '../utils/cjs'
import { defineNuxtCommand } from './index'

const MODULE_BUILDER_PKG = '@nuxt/module-builder'

export default defineNuxtCommand({
meta: {
name: 'build-module',
usage: 'npx nuxi build-module [--stub] [rootDir]',
description: `Helper command for using ${MODULE_BUILDER_PKG}`
},
async invoke (args) {
// Find local installed version
const rootDir = resolve(args._[0] || '.')
const hasLocal = tryResolveModule(`${MODULE_BUILDER_PKG}/package.json`, rootDir)

const execArgs = Object.entries({
'--stub': args.stub
}).filter(([, value]) => value).map(([key]) => key)

let cmd = 'nuxt-module-build'
if (!hasLocal) {
consola.warn(`Cannot find locally installed version of \`${MODULE_BUILDER_PKG}\` (>=0.2.0). Falling back to \`npx ${MODULE_BUILDER_PKG}\``)
cmd = 'npx'
execArgs.unshift(MODULE_BUILDER_PKG)
}

await execa(cmd, execArgs, { preferLocal: true, stdio: 'inherit', cwd: rootDir })
}
})
1 change: 1 addition & 0 deletions packages/nuxi/src/commands/index.ts
Expand Up @@ -5,6 +5,7 @@ const _rDefault = (r: any) => r.default || r
export const commands = {
dev: () => import('./dev').then(_rDefault),
build: () => import('./build').then(_rDefault),
'build-module': () => import('./build-module').then(_rDefault),
cleanup: () => import('./cleanup').then(_rDefault),
clean: () => import('./cleanup').then(_rDefault),
preview: () => import('./preview').then(_rDefault),
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/package.json
Expand Up @@ -58,7 +58,7 @@
"knitwork": "^0.1.2",
"magic-string": "^0.26.7",
"mlly": "^0.5.16",
"nitropack": "npm:nitropack-edge@0.5.5-27764245.b884d0c",
"nitropack": "npm:nitropack-edge@0.6.0-27765421.6d4b416",
"nuxi": "3.0.0-rc.11",
"ohash": "^0.1.5",
"ohmyfetch": "^0.4.19",
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack/src/plugins/dynamic-base.ts
Expand Up @@ -21,7 +21,7 @@ export const DynamicBasePlugin = createUnplugin((options: DynamicBasePluginOptio
return
}
const s = new MagicString(code)
s.append(`${options.globalPublicPath} = buildAssetsURL();\n`)
s.append(`\n${options.globalPublicPath} = buildAssetsURL();\n`)
return {
code: s.toString(),
map: options.sourcemap
Expand Down
2 changes: 1 addition & 1 deletion test/basic.test.ts
Expand Up @@ -234,7 +234,7 @@ describe('pages', () => {
expect(html).toContain('<div class="lazy-client-only-script-setup" foo="hello">')
// ensure components are not rendered server-side
expect(html).not.toContain('client only script')
await expectNoClientErrors('/client-only-components')
await expectNoClientErrors('/client-only-explicit-import')
})
})

Expand Down

0 comments on commit 4154eee

Please sign in to comment.