Last active
October 16, 2019 06:23
-
-
Save potato4d/62b3aa45bc35baf3bee5d6d611f10caf to your computer and use it in GitHub Desktop.
【実録】Nuxt.jsの既存プロジェクトを一足早くNuxt v2へとアップグレードする方法 ref: https://qiita.com/potato4d/items/7b3119c88869d7622a7d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default async function(context) { | |
- const { app, store, route, redirect, isServer, req } = context | |
+ const { app, store, route, redirect, req } = context | |
- if (isServer) { | |
+ if (process.server) { | |
// 認証の処理 | |
} else { | |
// クライアントでの処理 | |
} | |
// ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function ({ $axios, store }) { | |
$axios.onRequest((config) => { | |
if (store.state.token) { | |
config.headers.common['Authorization'] = store.state.token | |
} | |
return config | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[potato4d@snowcat sequeue-web (master)] $ yarn remove nuxt @nuxtjs/axios | |
yarn remove v1.6.0 | |
[1/3] 🗑 Removing module nuxt... | |
[2/3] 🗑 Removing module @nuxtjs/axios... | |
[3/3] 📃 Regenerating lockfile and installing missing dependencies... | |
success Uninstalled packages. | |
✨ Done in 11.43s. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[potato4d@snowcat sequeue-web (master)]$ yarn add nuxt-edge @nuxtjs/axios | |
yarn add v1.6.0 | |
[1/4] 🔍 Resolving packages... | |
[2/4] 🚚 Fetching packages... | |
[3/4] 🔗 Linking dependencies... | |
[4/4] 📃 Building fresh packages... | |
success Saved lockfile. | |
success Saved 527 new dependencies. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
クライアントビルド: | |
Version: webpack 3.10.0 | |
Time: 22505ms | |
サーバーバンドルの作成: | |
Version: webpack 3.10.0 | |
Time: 4903ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
クライアントビルド: | |
Version: webpack 4.7.0 | |
Time: 19148ms | |
Built at: 2018-05-07 21:08:09 | |
サーバーバンドルの作成: | |
Version: webpack 4.7.0 | |
Time: 4491ms | |
Built at: 2018-05-07 21:08:14 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// ... | |
axios: { | |
credentials: false, | |
baseURL: process.env.NODE_ENV == 'production' ? 'https://~~~~~~~~~~~~~' : 'http://localhost:8000', | |
requestInterceptor: (config, { store }) => { | |
if (store.state.token) { | |
config.headers.common['Authorization'] = store.state.token | |
} | |
return config | |
} | |
}, | |
// ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
... | |
"dependencies": { | |
"@nuxtjs/axios": "^5.3.1", | |
"@nuxtjs/toast": "^3.0.1", | |
"@potato4d/jpy": "^0.0.1", | |
"cookie": "^0.3.1", | |
"delay": "^2.0.0", | |
"js-cookie": "^2.2.0", | |
"lodash": "^4.17.4", | |
"nuxt-edge": "^2.0.0-25425967.7d92486" | |
}, | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment