Skip to content

Commit

Permalink
feat!: migrate to nitropack (nuxt#3956)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Roe <[email protected]>
  • Loading branch information
pi0 and danielroe authored Apr 7, 2022
1 parent 7d1ff39 commit 11626ee
Show file tree
Hide file tree
Showing 132 changed files with 751 additions and 4,371 deletions.
6 changes: 3 additions & 3 deletions docs/content/2.guide/2.features/10.runtime-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ export default defineNuxtPlugin((nuxtApp) => {
const config = useRuntimeConfig();

const url = process.server ? config.serverUrl : config.clientUrl;

// Do something with url & isServer.
});
```

### API routes

Within the API routes, you can access runtime config by directly importing from virtual `#config`.
Within the API routes, you can access runtime config by directly importing from virtual `#nitro`.

```ts
import config from '#config'
import { useRuntimeConfig } from '#nitro'

export default async () => {
const result = await $fetch('https://my.api.com/test', {
Expand Down
2 changes: 1 addition & 1 deletion docs/content/2.guide/5.deployment/1.azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ How to deploy Nuxt to Azure Static Web Apps or Azure Functions.
```ts [nuxt.config.js|ts]
export default {
nitro: {
preset: 'azure_functions'
preset: 'azure-functions'
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/content/2.guide/5.deployment/5.pm2.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Make sure another preset isn't set in `nuxt.config`.
export default {
nitro: {
// this is the default preset so you can also just omit it entirely
// preset: 'server'
// preset: 'node-server'
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/content/2.guide/5.deployment/99.presets/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default {
You can also define a preset in a separate file (or publish as a separate npm package).

```ts [my-preset/index.ts]
import type { NitroPreset } from '@nuxt/nitro'
import type { NitroPreset } from 'nitropack'

const myPreset: NitroPreset = {
// Your custom configuration
Expand Down
2 changes: 1 addition & 1 deletion docs/content/2.guide/5.deployment/99.presets/lambda.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ You can use the [Nuxt config](/guide/directory-structure/nuxt.config) to explici
```ts [nuxt.config.js|ts]
export default {
nitro: {
preset: 'lambda'
preset: 'aws-lambda'
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/content/2.guide/5.deployment/99.presets/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ You can use the [Nuxt config](/guide/directory-structure/nuxt.config) to explici
```js [nuxt.config.js|ts]
export default {
nitro: {
preset: 'server'
preset: 'node-server'
}
}
```
Expand Down Expand Up @@ -61,7 +61,7 @@ You can enable the `nitro.timing` option to have the logs about the chunk loadin
```js [nuxt.config.js|ts]
export default {
nitro: {
preset: 'server',
preset: 'node-server',
timing: true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ You can use the [Nuxt config](/guide/directory-structure/nuxt.config) to explici
```js [nuxt.config.js|ts]
export default {
nitro: {
preset: 'worker'
'browser-worker'
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/content/migration/8.runtime-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ head.titleTemplate: ''

If you wish to reference environment variables within your Nuxt 3 app, you will need to use runtime config.

When referencing these variables within your components, you will have to use the `useRuntimeConfig` composable in your setup method (or Nuxt plugin). In the `server/` portion of your app, you can import directly from `#config`.
When referencing these variables within your components, you will have to use the `useRuntimeConfig` composable in your setup method (or Nuxt plugin). In the `server/` portion of your app, you can import `useRuntimeConfig` directly from `#nitro`.

[Read more about runtime config](/guide/features/runtime-config).

Expand Down Expand Up @@ -41,7 +41,7 @@ export default defineNuxtConfig({
```

```ts [server/api/hello.ts]
import config from '#config'
import { useRuntimeConfig } from '#nitro';

export default (req, res) => {
// you can now access config.BASE_URL
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"dev:build": "yarn run nuxi build playground",
"release": "yarn && yarn lint && FORCE_COLOR=1 lerna publish -m \"chore: release\" && yarn stub",
"stub": "lerna run prepack -- --stub",
"test:fixtures": "yarn nuxi prepare test/fixtures/basic && JITI_ESM_RESOLVE=1 vitest --dir test",
"test:fixtures": "yarn nuxi prepare test/fixtures/basic && JITI_ESM_RESOLVE=1 vitest run --dir test",
"test:fixtures:webpack": "TEST_WITH_WEBPACK=1 yarn test:fixtures",
"test:types": "yarn run nuxi prepare test/fixtures/basic && cd test/fixtures/basic && npx vue-tsc --noEmit",
"test:unit": "JITI_ESM_RESOLVE=1 yarn vitest --dir packages",
"test:unit": "JITI_ESM_RESOLVE=1 yarn vitest run --dir packages",
"version": "yarn && git add yarn.lock"
},
"resolutions": {
Expand Down
5 changes: 3 additions & 2 deletions packages/bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"@babel/plugin-proposal-optional-chaining": "^7.16.7",
"@babel/plugin-transform-typescript": "^7.16.8",
"@nuxt/kit": "3.0.0",
"@nuxt/nitro": "3.0.0",
"@nuxt/postcss8": "^1.1.3",
"@nuxt/schema": "3.0.0",
"@vitejs/plugin-legacy": "^1.8.0",
Expand All @@ -38,12 +37,13 @@
"externality": "^0.2.1",
"fs-extra": "^10.0.1",
"globby": "^13.1.1",
"h3": "^0.4.2",
"h3": "^0.7.1",
"hash-sum": "^2.0.0",
"knitwork": "^0.1.1",
"magic-string": "^0.26.1",
"mlly": "^0.5.1",
"murmurhash-es": "^0.1.1",
"nitropack": "^0.1.0",
"node-fetch": "^3.2.3",
"nuxi": "3.0.0",
"ohash": "^0.1.0",
Expand All @@ -63,6 +63,7 @@
"untyped": "^0.4.4",
"vite": "^2.9.1",
"vite-plugin-vue2": "^1.9.3",
"vue-bundle-renderer": "^0.3.5",
"vue-template-compiler": "^2.6.14"
},
"devDependencies": {
Expand Down
7 changes: 6 additions & 1 deletion packages/bridge/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useNuxt, addTemplate, resolveAlias, addWebpackPlugin, addVitePlugin } from '@nuxt/kit'
import { useNuxt, addTemplate, resolveAlias, addWebpackPlugin, addVitePlugin, addPlugin } from '@nuxt/kit'
import { NuxtModule } from '@nuxt/schema'
import { resolve } from 'pathe'
import { componentsTypeTemplate } from '../../nuxt3/src/components/templates'
Expand Down Expand Up @@ -94,4 +94,9 @@ export function setupAppBridge (_options: any) {
})
}
})

addPlugin({
src: resolve(distDir, 'runtime/error.plugin.server.mjs'),
mode: 'server'
})
}
4 changes: 3 additions & 1 deletion packages/bridge/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export default defineNuxtModule({
}]

if (opts.nitro) {
await setupNitroBridge()
nuxt.hook('modules:done', async () => {
await setupNitroBridge()
})
}
if (opts.app) {
await setupAppBridge(opts.app)
Expand Down
Loading

0 comments on commit 11626ee

Please sign in to comment.