Skip to content

Instantly share code, notes, and snippets.

@potato4d
Last active October 16, 2019 06:23
Show Gist options
  • Save potato4d/62b3aa45bc35baf3bee5d6d611f10caf to your computer and use it in GitHub Desktop.
Save potato4d/62b3aa45bc35baf3bee5d6d611f10caf to your computer and use it in GitHub Desktop.
【実録】Nuxt.jsの既存プロジェクトを一足早くNuxt v2へとアップグレードする方法 ref: https://qiita.com/potato4d/items/7b3119c88869d7622a7d
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 {
// クライアントでの処理
}
// ...
}
export default function ({ $axios, store }) {
$axios.onRequest((config) => {
if (store.state.token) {
config.headers.common['Authorization'] = store.state.token
}
return config
})
}
[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.
[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.
クライアントビルド:
Version: webpack 3.10.0
Time: 22505ms
サーバーバンドルの作成:
Version: webpack 3.10.0
Time: 4903ms
クライアントビルド:
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
{
// ...
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
}
},
// ...
}
{
...
"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