Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Demystifying Nuxt Bridge
Search
wattanx
October 29, 2023
Programming
7.8k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Demystifying Nuxt Bridge
Vue Fes 2023
wattanx
wattanx
October 29, 2023
More Decks by wattanx
See All by wattanx
Nuxt Server Components
wattanx
0
540
フロントエンド技術選定の裏側
wattanx
1
130
Unlocking the potential of Nuxt Server Components
wattanx
2
790
Deep dive into Nuxt Server Components
wattanx
1
4.1k
Nuxt Test Utils で始める効率的な Nuxt アプリケーションのテスト
wattanx
4
4.4k
小さく進める Nuxt 3 移行
wattanx
0
2.1k
プロダクト開発を止めずに Composition API と TypeScript に 最速で移行するための戦い
wattanx
0
2.4k
Other Decks in Programming
See All in Programming
Webの地図
yosuke_furukawa
PRO
6
4.7k
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
130
AWSに止められる覚悟してますか?
morizo_1984
1
270
Intent as Code
shoppingjaws
6
1.1k
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
520
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
340
新卒PdEのリアル
ryu1013
1
510
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
540
SONY CISC-NEWS NWS-1750 + NWB-225 フレームバッファの NetBSD/news68k ドライバ実装 / OSC2026Hiroshima
tsutsui
0
150
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
2
300
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
17
15k
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
8.4k
Featured
See All Featured
Ethics towards AI in product and experience design
skipperchong
2
380
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.8k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
Product Roadmaps are Hard
iamctodd
55
13k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
Rails Girls Zürich Keynote
gr2m
96
14k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
260
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
300
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
560
Paper Plane (Part 1)
katiecoart
PRO
2
11k
Google's AI Overviews - The New Search
badams
0
1.6k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Transcript
STORES 株式会社 Demystifying Nuxt Bridge 〜 あなたがまだ見ぬ可能性とその活用法〜
目次 2 自己紹介 はじめに Nuxt Bridge を使った Nuxt 3 移行
Nuxt Bridge でもできない Nuxt 3 移行 STORES の事例 まとめ 01 02 03 04 05 06
自己紹介
渡邊 涼太(wattanx) ・STORES 株式会社 ソフトウェアエンジニア。 ・STORES ネットショップの開発に関わっている。 ・猫が好き。大阪在住。 ・Nuxt Bridge
のコアコントリビュータ。 ・https://twitter.com/pontaxx 自己紹介
はじめに
はじめに(今日話すこと) どのように Nuxt Bridge を導入して Nuxt 3 移行を進めるのがよいかを話します
はじめに(今日話さないこと) Nuxt 2 の機能や Nuxt 3 の機能はあまり深掘りません
はじめに Nuxt Bridge を知っていますか?
はじめに • https://github.com/nuxt/bridge • Nuxt 3 と上方互換性のあるライブラリ (Nuxt 3 の機能の一部が
Nuxt 2 でも使えるようなる) Nuxt Bridge とは
はじめに Nuxt 2 のプロジェクトで Nuxt 3 の機能を体験できる
はじめに Nuxt 2 のプロジェクトで Nuxt 3 の機能を体験できる
はじめに Nuxt 3 との差分を減らし、 Nuxt 3 への移行の負担を減らす
はじめに どれくらい Nuxt 3 との差分が少なくなるのか
はじめに https://github.com/wattanx/nuxt-migration-example
はじめに Nuxt 2 の状態で どれくらい Nuxt 3 への移行が進められるか
はじめに Bridgeでもできる Bridgeでもできる Bridgeでもできる Bridgeでもできる Bridgeでもできる Bridgeでもできる Bridgeでもできる Bridgeでもできる Bridgeでもできる
Bridgeでも一部できる
はじめに Nuxt Bridge の導入って何をするのか Nuxt Bridge 入れた Nuxt 3 移行ってどうやるのか
Nuxt Bridge を使った Nuxt 3 移行
Nuxt Bridge を使った Nuxt 3 移行 (Nuxt Bridge の導入) Nuxt
Bridge のインストール 〜 設定完了まで
Nuxt Bridge を使った Nuxt 3 移行 (Nuxt Bridge の導入) •
Nuxt 2 を最新バージョンにし、Nuxt Bridge をインストールする RCでも良い
Nuxt Bridge を使った Nuxt 3 移行 (Nuxt Bridge の導入) •
defineNuxtConfig つかうように修正する • bridge オプションを false にして config を設定する
Nuxt Bridge を使った Nuxt 3 移行 (Nuxt Bridge の導入) •
nuxt コマンドを nuxt2 コマンドに変更する
Nuxt Bridge を使った Nuxt 3 移行 (Nuxt Bridge の導入) •
@nuxt/cli (nuxi) が提供する nuxt コマンドと競合するので、nuxt2 に変更する必要がある。 ◦ Nuxt 3 では nuxt コマンドで nuxi を実行できるようにしている • 変更しない場合、nuxt 3 の nuxt コマンドだと認識されてしまう場合 がある。
Nuxt Bridge を使った Nuxt 3 移行 (Nuxt Bridge の導入) nuxt2
コマンドを実行してみてください 今までどおり Nuxt 2 のプロジェクトが動作するはず
Nuxt Bridge を使った Nuxt 3 移行 ここからは Nuxt 2 の状態でできる
Nuxt 3 移行
Nuxt Bridge を使った Nuxt 3 移行 • TypeScript • Plugins
and Middleware • Migrate New Composition API • Migrate Legacy Composition API • Meta Tags • Runtime Config • Nitro • Vite
Nuxt Bridge を使った Nuxt 3 移行 全部一度に対応する必要はない 少しずつ移行できる(Nuxt Bridge のメリット)
Nuxt Bridge を使った Nuxt 3 移行(TypeScript) • https://nuxt.com/docs/bridge/typescript • Nuxt
3 では @nuxt/typescript-build や @nuxt/typescript-runtime といったModule は もう必要ありません。 • Nuxt 3 と同じように TypeScript が利用できる。 TypeScript
• bridge.typescript オプションを true にする Nuxt Bridge を使った Nuxt 3
移行(TypeScript)
Nuxt Bridge を使った Nuxt 3 移行(TypeScript) • @nuxt/typescript-build や @nuxt/typescript-runtime
などの Module を削除する • tsconfig.json を修正する
Nuxt Bridge を使った Nuxt 3 移行(TypeScript) • tsconfig を拡張したい場合、nuxt.config にて設定する必要がある。
◦ https://nuxt.com/docs/api/configuration/nuxt-config#tsconfig • compilerOptions.paths を拡張したいときは、nuxt.config の alias に設定する必要がある。 ◦ https://nuxt.com/docs/api/configuration/nuxt-config#alias 注意点
Nuxt Bridge を使った Nuxt 3 移行(Plugins and Middleware) • https://nuxt.com/docs/bridge/plugins-and-middleware
• Nuxt 2 と Nuxt 3 では Plugins と Middleware の設定方法が大 きく変わる。 • Nuxt 3 と同じ書き方で Plugins や Middleware が設定できる。 Plugins and Middleware
Nuxt Bridge を使った Nuxt 3 移行(Plugins and Middleware) defineNuxtPlugin に変更する
Nuxt Bridge を使った Nuxt 3 移行(Plugins and Middleware) • Nuxt
3 では plugins ディレクトリの一番上の階層に配置され たファイルしか認識されない。 ◦ https://nuxt.com/docs/guide/directory-structure/p lugins#which-files-are-registered • Nuxt 2 のうちにディレクトリ構造を見直しておいた方がよい Plugins
Nuxt Bridge を使った Nuxt 3 移行(Plugins and Middleware) defineNuxtRouteMiddleware に変更する
Nuxt Bridge を使った Nuxt 3 移行(Migrate New Composition API) •
https://nuxt.com/docs/bridge/nuxt3-compatible-api • Nuxt2 では、@nuxtjs/composition-api を利用していた • Nuxt 3 では利用できないので、別の関数などに書き換える 必要がある。 • Nuxt 3 で提供される useNuxtApp などの関数は、Nuxt Bridge でも利用できる。 (Auto Import も使える) Migrate New Composition API
Nuxt Bridge を使った Nuxt 3 移行(Migrate New Composition API) 量が多いので一部を抜粋
• useContext -> useNuxtApp • Auto Import を使わない場合
Nuxt Bridge を使った Nuxt 3 移行(Migrate New Composition API) •
@nuxtjs/composition-api と併用できる。 • 1ページずつ、1コンポーネントずつみたいなかたちですこしずつ移行 できる。 Tips
Nuxt Bridge を使った Nuxt 3 移行 Nuxt 3 との差分少なくなってますよね
Nuxt Bridge を使った Nuxt 3 移行(Migrate Legacy Composition API) •
https://nuxt.com/docs/bridge/bridge-composition-api • @nuxtjs/composition-api の機能は全部 Nuxt Bridge に入った • この Migration を行わずに Migrate New Composition API を やってもいい Migrate Legacy Composition API
Nuxt Bridge を使った Nuxt 3 移行(Migrate Legacy Composition API) bridge.capi
オプションを true にする
Nuxt Bridge を使った Nuxt 3 移行(Migrate Legacy Composition API) •
@vue/composition-api や @nuxtjs/composition-api などの Module を削除する • 一部の関数は削除されていたり変更があるので対応する
Nuxt Bridge を使った Nuxt 3 移行(Migrate Legacy Composition API) •
@nuxtjs/composition-api という alias が Nuxt Bridge により提供 されているので、import文 を書き換える必要はなし (.nuxt/tsconfig.json)
Nuxt Bridge を使った Nuxt 3 移行 • TypeScript • Plugins
and Middleware • Migrate New Composition API • Migrate Legacy Composition API • Meta Tags(次はここの説明) • Runtime Config • Nitro • Vite
Nuxt Bridge を使った Nuxt 3 移行 全部一度に対応する必要はない 少しずつ移行できる(Nuxt Bridge のメリット)
Nuxt Bridge を使った Nuxt 3 移行(Meta Tags) • https://nuxt.com/docs/bridge/meta •
Nuxt 2 では useMeta という Composables をつかっていた。 • Nuxt 3 からは useHead に変更されている。 • Nuxt 3 同様 useHead が利用できる。 (@unhead/vue を使用) Meta Tags
Nuxt Bridge を使った Nuxt 3 移行(Meta Tags) bridge.meta オプションを true
にする
Nuxt Bridge を使った Nuxt 3 移行(Meta Tags) config を変更する app.head
に変更する
Nuxt Bridge を使った Nuxt 3 移行(Meta Tags) useMeta ではなく useHead
を使う (Options API の場合は defineNuxtComponent を使う)
Nuxt Bridge を使った Nuxt 3 移行(Meta Tags) nuxt.config の titleTemplate
は関数で設定できないので注意 ↓のようなコードを /layouts に含める必要がある。 注意点
Nuxt Bridge を使った Nuxt 3 移行(Nitro) • https://nuxt.com/docs/bridge/nitro • Nuxt
3 から Nitro というサーバーエンジンに変更されている。 • Nuxt Bridge でも Nitro が利用できる Nitro
Nuxt Bridge を使った Nuxt 3 移行(Nitro) bridge.nitro オプションを true にする
Nuxt Bridge を使った Nuxt 3 移行(Nitro) • @nuxt/nitro を削除する •
nuxi をインストールする • .gitignore に .output を追加する
Nuxt Bridge を使った Nuxt 3 移行(Nitro) • nuxt2 コマンドから nuxi
コマンドに変更する • target: static なら nuxi generate
Nuxt Bridge を使った Nuxt 3 移行(Nitro) nuxi dev コマンドを実行してみてください
Nuxt Bridge を使った Nuxt 3 移行(Nitro) • ~/server/middleware や ~/server/api
も利用できる https://nuxt.com/docs/guide/directory-structure/server
Nuxt Bridge を使った Nuxt 3 移行(Nitro) • Nitro にすると動かなくなる Nuxt
Module がある。 ◦ 例えば @nuxtjs/proxy 注意点
Nuxt Bridge を使った Nuxt 3 移行(Runtime Config) • https://nuxt.com/docs/bridge/runtime-config •
Nuxt 2 では publicRuntimeConfig や privateRuntimeConfig • Nuxt 3 では runtimeConfig に変更された • Nuxt Bridge でも runtimeConfig が利用できる。 (しかし Nitro を使える状態にあることが前提) Runtime Config
Nuxt Bridge を使った Nuxt 3 移行(Runtime Config) nuxt.config を修正する
Nuxt Bridge を使った Nuxt 3 移行(Runtime Config) useRuntimeConfig で nuxt.config
で設定した値が使える
Nuxt Bridge を使った Nuxt 3 移行(Vite) • https://nuxt.com/docs/bridge/vite • Nuxt
3 から webpack と Vite も選択できる。 • Nuxt Bridge でも Vite が利用できる。 (ただし、Nitro が使える状態であることが前提) Vite
Nuxt Bridge を使った Nuxt 3 移行(Vite) bridge.vite オプションを true にする
Nuxt Bridge を使った Nuxt 3 移行(Vite) • require を使った 動的
Asset URL が使えない ◦ :src=”require(‘@/images/hoge.png’)”のようなコード • 使えなくなる Nuxt Module がある。(@nuxt/sentry など) • 他にもあるかも... Vite に移行するならやることいっぱいある
Nuxt Bridge を使った Nuxt 3 移行 ほぼ Nuxt 3 です
Nuxt Bridge でもできない Nuxt 3 移行
Nuxt Bridge でもできない Nuxt 3 移行 Nuxt 3 への移行ガイドを参考に
Nuxt Bridge でもできない Nuxt 3 移行 • Configuration • Vue
3 への移行 • Vuex • Pages and Layouts
Nuxt Bridge でもできない Nuxt 3 移行 • https://nuxt.com/docs/migration/configuration • buildModules
-> modules へ置き換え • router.extendRoutes -> pages:extend hook Configuration
Nuxt Bridge でもできない Nuxt 3 移行 • https://v3-migration.vuejs.org/ • やるしかない
Vue 3 への移行
Nuxt Bridge でもできない Nuxt 3 移行 • https://nuxt.com/docs/migration/configuration#vuex • Nuxt
2 では store ディレクトリを使うだけで Vuex が使えた • Nuxt 3 では store ディレクトリがサポートされなくなる • Nuxt 3 では Pinia の使用が推奨されている。 (useState でも代替可能) Vuex
Nuxt Bridge でもできない Nuxt 3 移行 Nuxt 3 でも store
ディレクトリを使って Vuex を使えるようにする module がある https://github.com/wattanx/nuxt-vuex-module
Nuxt Bridge でもできない Nuxt 3 移行 • https://nuxt.com/docs/migration/pages-and-layouts • app.vue
の作成 • Layout の <Nuxt /> を <slot /> に変更する • Dynamic Routes ◦ 例えば _id.vue を [id].vue に変更する必要がある • Nested Routes ◦ 例えば <NuxtChild /> を <NuxtPage /> に変更する必要がある Pages and Layouts
Nuxt Bridge でもできない Nuxt 3 移行 • https://nuxt.com/docs/api/utils/define-page-meta#definepagemeta • middleware
や layout の指定が Component Option からできな くなる。 • layout と middleware のみ Nuxt Bridge でもサポートしている • layout と middleware 以外の移行作業が必要 definePageMeta
Nuxt Bridge でもできない Nuxt 3 移行 Nuxt Bridge でもできそうならぜひ Pull
Request を
STORES の事例
STORES の事例 自分でつくれる、 本格的なネットショップ むずかしい知識や技術いらずで 自分だけのネットショップをかんたんに。
STORES の事例 ネットショップを開設した事業者が触る 管理画面を Nuxt 3 に移行しようとしている
STORES の事例(なぜ Nuxt 3 へ移行するのか) Vue 3 使いたい
STORES の事例(なぜ Nuxt 3 へ移行するのか) Nuxt 2 の EOL は
2024/6/30
STORES の事例 STORES はどのような順番で進めているのか
STORES の事例
STORES の事例
STORES の事例 • TypeScript • Migrate Legacy Composition API ◦
必要だと思ってたので対応した • Migrate New Composition API • Meta Tags • Plugins and Middleware • Nitro(これから) • Runtime Config(これから) Nuxt Bridge を使った Nuxt 3 移行
STORES の事例 • Vitest への移行 • Vue 2.7 移行 •
Vue 3 移行 ◦ Vue 2 の状態でできる移行を先にやる。 ▪ Vue Test Utils の wrapper を作成したり極力差分を減らす ようにしている。 ◦ 社内ライブラリの Vue 3 移行を並行して進める。 Nuxt Bridge を使った Nuxt 3 移行以外
STORES の事例 • ネットショップ管理画面の Nuxt Bridge を使った Nuxt 3 移行
◦ Nitro ◦ Runtime Config ◦ 一旦 webpack で動かす予定なので Vite には移行しない • ネットショップ管理画面の Nuxt Bridge ではできない Nuxt 3 移行 あとなにが残っているのか
STORES の事例 おすすめの移行方法
STORES の事例 • 以下の対応を行う。(どれからやってもいい、並行して進めてもいい) ◦ TypeScript ◦ Migrate New Composition
API ◦ Plugins and Middleware ◦ Meta Tags ◦ Nitro • Nuxt Bridge ではできない Nuxt 3 移行をする 我々が考えるおすすめの移行方法
STORES の事例 • Vue 3 移行も並行で進めるのが良い。 ◦ Vue 2 の状態でできる移行がある
• Nuxt Modules が Nuxt 3 に対応しているのか調査しておくのが良い。 ◦ 自作しなければならない場合があるため。 • script setup への移行も並行できると良い。 ◦ https://wattanx-converter.vercel.app/vue-composition-converter/ ◦ https://wattanx-converter.vercel.app/vue-script-setup-converter/ 我々が考えるおすすめの移行方法
まとめ
まとめ Nuxt 2 のプロジェクトで Nuxt 3 の機能を体験できる
まとめ Nuxt 2 のプロジェクトで Nuxt 3 の機能を体験できる
まとめ Nuxt 3 との差分を減らし、 Nuxt 3 への移行の負担を減らす
まとめ 少しずつ Nuxt 3 に向けたマイグレーションができるのが Nuxt Bridge の良いところ
まとめ 紹介した移行方法がすべてではない
まとめ より良い方法があればぜひ Pull Request を
まとめ 今日話したことは全部ドキュメントに書きました https://nuxt.com/docs/bridge/overview
おまけ いまから Nuxt Bridge RC.2 をリリースします