• Stars
    star
    263
  • Rank 150,405 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 2 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐ŸŒ‰ Experience Nuxt 3 features on existing Nuxt 2 projects

๐ŸŒ‰ Nuxt Bridge

Experience Nuxt 3 features on existing Nuxt 2 projects.

Bridge is a forward-compatibility layer that allows you to experience many of the new Nuxt 3 features by simply installing and enabling a Nuxt module.

Using Nuxt Bridge, you can make sure your project is (almost) ready for Nuxt 3 and have the best developer experience without needing a major rewriteย or risk breaking changes.

โš ๏ธ Note: Nuxt Bridge provides identical features to Nuxt 3 (Nuxt 3 docs) but there are some limitations, notably that useAsyncData and useFetch composables are not available. Please read the rest of this page for details.

โš ๏ธ Note: Nuxt Bridge does not support Internet Explorer. Supported browsers are listed at https://caniuse.com/es6-module-dynamic-import.

๐ŸŒฑ Note: If you're starting a fresh Nuxt project, please skip this module and directly go to the Nuxt 3 Installation.

๐Ÿ’ป Development

  • Clone repository
  • Ensure you have the latest LTS version of Node.js installed
  • Enable Corepack using corepack enable to enable pnpm and yarn
  • Install dependencies with pnpm install
  • Run pnpm dev:prepare to activate passive development
  • Open playground with pnpm dev

Learn more about in our documentation on how to contribute to Nuxt.

Installation

Upgrade to the latest Nuxt 2

Make sure your dev server (nuxt dev) isn't running, remove any package lock files (package-lock.json, yarn.lock or pnpm-lock.yaml), and install the latest nuxt version:

- "nuxt": "^2.15.0"
+ "nuxt": "^2.16.0"

Then, reinstall your dependencies:

# Using yarn
yarn install

# Using npm
npm install

# Using pnpm
pnpm install

Once the installation is complete, make sure both development and production builds are working as expected before proceeding.

Install Nuxt Bridge

Install @nuxt/bridge-edge as a development dependency:

# Using yarn
yarn add --dev @nuxt/bridge@npm:@nuxt/bridge-edge

# Using npm
npm install -D @nuxt/bridge@npm:@nuxt/bridge-edge

# Using pnpm
pnpm install -D @nuxt/bridge@npm:@nuxt/bridge-edge

Update your scripts

You will also need to update your scripts within your package.json to reflect the fact that Nuxt will now produce a Nitro server as build output.

Nuxi

Nuxt 3 introduced the new Nuxt CLI command nuxi. Update your scripts as follows to leverage the better support from Nuxt Bridge:

{
  "scripts": {
-   "dev": "nuxt",
+   "dev": "nuxi dev",
-   "build": "nuxt build",
+   "build": "nuxi build",
-   "start": "nuxt start",
+   "start": "nuxi preview"
  }
}

Static target

If you have set target: 'static' in your nuxt.config then you need to ensure that you update your build script to be nuxi generate.

{
  "scripts": {
    "build": "nuxi generate"
  }
}

Server target

For all other situations, you can use the nuxi build command.

{
  "scripts": {
    "build": "nuxi build",
    "start": "nuxi preview"
  }
}

Update nuxt.config

Please make sure to avoid any CommonJS syntax such as module.exports, require or require.resolve in your config file. It will soon be deprecated and unsupported.

You can use static import, dynamic import() and export default instead. Using TypeScript by renaming to nuxt.config.ts is also possible and recommended.

import { defineNuxtConfig } from '@nuxt/bridge'

export default defineNuxtConfig({
  // Your existing configuration
})

Update tsconfig.json

If you are using TypeScript, you can edit your tsconfig.json to benefit from auto-generated Nuxt types:

{
+ "extends": "./.nuxt/tsconfig.json",
  "compilerOptions": {
    ...
  }
}

Keep in mind that all options extended from ./.nuxt/tsconfig.json will be overwritten by the options defined in your tsconfig.json.

Overwriting options such as "compilerOptions.paths" with your own configuration will lead TypeScript to not factor in the module resolutions from ./.nuxt/tsconfig.json. This can lead to module resolutions such as #imports not being recognized.

In case you need to extend options provided by ./.nuxt/tsconfig.json further, you can use the alias property withing your nuxt.config. nuxi will pick them up and extend ./.nuxt/tsconfig.json accordingly.

Migrate Composition API

If you were using @vue/composition-api or @nuxtjs/composition-api, please read the composition api migration guide.

Migrate from CommonJS to ESM

Nuxt 3 natively supports TypeScript and ECMAScript Modules. Please check Native ES Modules for more info and upgrading.

Remove incompatible and obsolete modules

  • Remove @nuxt/content (1.x). A rewrite for Nuxt 3 is planned (2.x)
  • Remove nuxt-vite: Bridge enables same functionality
  • Remove @nuxt/typescript-build: Bridge enables same functionality
  • Remove @nuxt/typescript-runtime and nuxt-ts: Nuxt 2 has built-in runtime support
  • Remove @nuxt/nitro: Bridge injects same functionality
  • Remove @vue/composition-api from your dependencies (migration guide).
  • Remove @nuxtjs/composition-api from your dependencies (and from your modules in nuxt.config) (migration guide).

Exclude built Nitro folder from git

Add the folder .output to the .gitignore file.

Ensure everything goes well

โœ”๏ธ Try with nuxi dev and nuxi build (or nuxi generate) to see if everything goes well.

๐Ÿ› Is something wrong? Please let us know by creating an issue. Also, you can easily disable the bridge in the meantime:

import { defineNuxtConfig } from '@nuxt/bridge'

export default defineNuxtConfig({
  bridge: false // Temporarily disable bridge integration
})

New plugins format (optional)

You can now migrate to the Nuxt 3 plugins API, which is slightly different in format from Nuxt 2.

Plugins now take only one argument (nuxtApp). You can find out more in the docs.

export default defineNuxtPlugin(nuxtApp => {
  nuxtApp.provide('injected', () => 'my injected function')
  // now available on `nuxtApp.$injected`
})

If you want to use the new Nuxt composables (such as useNuxtApp or useRuntimeConfig) within your plugins, you will need to use the defineNuxtPlugin helper for those plugins.

Although a compatibility interface is provided via nuxtApp.vueApp you should avoid registering plugins, directives, mixins or components this way without adding your own logic to ensure they are not installed more than once, or this may cause a memory leak.

New useHead (optional)

Nuxt Bridge provides a new Nuxt 3 meta API that can be accessed with a new useHead composable.

<script setup>
useHead({
  title: 'My Nuxt App',
})
</script>

You will also need to enable this feature explicitly in your nuxt.config:

import { defineNuxtConfig } from '@nuxt/bridge'

export default defineNuxtConfig({
  bridge: {
    meta: true
  }
})

This useHead composable uses @vueuse/head under the hood (rather than vue-meta) to manipulate your <head>. Accordingly, we recommend not to use both the native Nuxt 2 head() properties as well as useHead, as they may conflict.

For more information on how to use this composable, see the docs.

Feature Flags

You can optionally disable some features from bridge or opt-in to less stable ones. In normal circumstances, it is always best to stick with defaults!

You can check packages/bridge/src/module.ts for latest defaults.

import { defineNuxtConfig } from '@nuxt/bridge'

export default defineNuxtConfig({
  bridge: {

    // -- Opt-in features --

    // Use Vite as the bundler instead of webpack 4
    // vite: true,

    // Enable Nuxt 3 compatible useHead
    // meta: true,


    // -- Default features --

    // Use legacy server instead of Nitro
    // nitro: false,

    // Use legacy generator rather than new nitro prerenderer
    // nitroGenerator: false,

    // Disable nuxt 3 compatible `nuxtApp` interface
    // app: false,

    // Disable Composition API support
    // capi: false,

    // ... or just disable legacy Composition API support
    // capi: {
    //   legacy: false
    // },

    // Do not transpile modules
    // transpile: false,

    // Disable composables auto importing
    // imports: false,

    // Do not warn about module incompatibilities
    // constraints: false
  },

  vite: {
    // Config for Vite
  }
})

License

MIT

More Repositories

1

nuxt

The Intuitive Vue Framework.
TypeScript
51,559
star
2

framework

Old repo of Nuxt 3 framework, now on nuxt/nuxt
10,721
star
3

awesome

A curated list of awesome things related to Nuxt.js
5,014
star
4

vue-meta

Manage HTML metadata in Vue.js components with SSR support
JavaScript
4,064
star
5

create-nuxt-app

Create Nuxt.js App in seconds.
JavaScript
3,451
star
6

ui

A UI Library for Modern Web Apps, powered by Vue & Tailwind CSS.
Vue
3,316
star
7

content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
TypeScript
2,976
star
8

devtools

Unleash Nuxt Developer Experience
Vue
2,681
star
9

website-v2

Nuxt 2 Documentation Website
Vue
2,241
star
10

movies

๐Ÿฟ A TMDB client built with Nuxt 3
Vue
1,818
star
11

vite

โšก Vite Experience with Nuxt 2
TypeScript
1,385
star
12

image

Plug-and-play image optimization for Nuxt applications.
TypeScript
1,247
star
13

hackernews

HackerNews clone built with Nuxt.
Vue
1,197
star
14

components

Scan and auto import components for Nuxt.js 2.13+
TypeScript
879
star
15

modules

Discover the Nuxt modules to add any CMS, Database, UI, Auth and integrations into your Vue application.
TypeScript
871
star
16

example-auth0

A simple example that shows how to use Nuxt.js with Auth0.
Vue
713
star
17

vercel-builder

Vercel Builder for Nuxt
TypeScript
641
star
18

typescript

TypeScript Support for Nuxt 2
TypeScript
567
star
19

docs

Old Documentation of Nuxt.js ๐Ÿ’š - not in use anymore
539
star
20

learn.nuxt.com

[Work in Progress] An interactive tutorial and playground for Nuxt
Vue
492
star
21

starter

Create a new Nuxt project, module, layer or start from a theme with our collection of starters.
382
star
22

eslint-config

ESlint config used for Nuxt
JavaScript
346
star
23

fonts

Plug-and-play web font optimization and configuration for Nuxt apps.
TypeScript
345
star
24

test-utils

๐Ÿงช Test utilities for Nuxt
TypeScript
273
star
25

assets

๐ŸŽจ Unified Assets and Templates for Nuxt
HTML
267
star
26

nuxt.com

The Nuxt website, made with Nuxt.
Vue
225
star
27

nuxt.new

Create a new Nuxt project from your address bar.
Vue
225
star
28

http

Universal HTTP Module for Nuxt.js
JavaScript
221
star
29

cli

โšก๏ธ Nuxt Generation CLI Experience.
TypeScript
207
star
30

module-builder

Complete solution to build Nuxt Modules.
TypeScript
202
star
31

nitro-demo

nuxt nitro preview
Vue
187
star
32

telemetry

Nuxt Telemetry
TypeScript
185
star
33

press

[Deprecated] Minimalist Markdown Publishing for Nuxt.js
JavaScript
184
star
34

todomvc

Nuxt.js TodoMVC Example
Vue
146
star
35

examples

Deployed Nuxt examples
TypeScript
134
star
36

eslint-plugin-nuxt

ESLint plugin for Nuxt.js [WIP]
JavaScript
129
star
37

nuxters

Vue
124
star
38

rfcs

RFCs for changes to Nuxt.js
97
star
39

loading-screen

Loading Screen Module for Nuxt.js
JavaScript
90
star
40

scripts

Plug-and-play script optimization for Nuxt applications. (Public Preview)
TypeScript
65
star
41

cli-draft

WIP: CLI for Nuxt.js projects
62
star
42

postcss8

Opt-in to postcss 8 in Nuxt 2 apps.
TypeScript
58
star
43

actions-yarn

Github Actions for yarn
Shell
47
star
44

codesandbox-nuxt

Starter template for CodeSandBox.io
Vue
43
star
45

blueprints

Module for Nuxt.js to create distributable micro-apps
JavaScript
41
star
46

benchmarks

๐Ÿ’จ Nuxt.js SSR performance Benchmarks
JavaScript
24
star
47

renovate-config-nuxt

Nuxt.js presets for Renovate tool.
18
star
48

nuxt-services-experimental

[WIP] Around realtime services for Nuxt 3
JavaScript
17
star
49

nuxt3-stubs

JavaScript
13
star
50

static

Fast Static Builder
TypeScript
12
star
51

governance

Nuxt Project Governance
12
star
52

babel-preset-app

PSA: this repo has been moved into nuxt.js/nuxt --> https://github.com/nuxt/nuxt.js/tree/dev/packages/babel-preset-app
JavaScript
10
star
53

nuxt-redirects

Nuxt.js redirects app for Netlify
9
star
54

.github

Default community health files for nuxt repositories
4
star