28
23

More than 5 years have passed since last update.

nuxtでgenerateしたファイルをローカルで実行する。

Posted at

nuxtでgenerateすればdistフォルダに書き出すことができますが、ローカルで確認しようとすると、
そのままではパスの関係上で上手く実行できない。それを実行できるようにした。

やることは以下の2つ。

相対パスで認識するように書き換え

nuxt.config.js
export default {
   if(!ctx.isDev) {
      config.output.publicPath = '_nuxt/'
   }
}

index.html のnot be found回避

index.htmlを開くと「This page could not be found」になるので、index.vueを表示するように回避した。

nuxt.config.js
export default {
  router: {
    extendRoutes (routes, resolve) {
      routes.push({
        name: 'custom',
        path: '*',
        component: resolve(__dirname, 'pages/index.vue')
      })
    }
  }
}

これで、サーバー無しに実行・確認できますね。

28
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
23