5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vue.js:ビルドしてサブディレクトリに置きたい

5
Posted at

「公式リファレンス見たら書いてあるじゃん」って話ですが、

http://example.com/
例えば、こんな感じのURLがあるとして、
http://example.com/hoge/
ココのhogeディレクトリ以下にビルドして置きたい。

デフォルトの設定だとドメイン直下「/」に書き出されちゃって、
フォルダをヒョイっと移動しただけではパスがズレてしまいます。
なのでどうするかというと

vue.config.jsを作る

$ touch vue.config.js
$ open vue.config.js
vue.config.js
module.exports = {
  publicPath: process.env.NODE_ENV === 'production'
    ? '/hoge/'
    : '/'
}

ちなみに自分のvue-cliは新しめです。
(バージョン3くらいからできるはず。)

ちなみにvue-cli-uiでも設定できますが、
条件分岐は書けないかも。

以上です。

■参考資料
https://cli.vuejs.org/config/#publicpath

5
4
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
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?