賞金將在 4 天后到期。此問題的答案有資格獲得 50聲望賞金。 迭戈·阿曼多·馬拉多納 (Diego Armando Maradona ) 希望引起對這個問題的更多關注。
我正在使用 Vite 構建 Vue3 專案,并且正在使用 Vite build.outDir選項在 Vue3 應用程式根目錄之外構建專案。這是我的專案結構,frontend檔案夾中包含 Vue3 應用程式:
my-app/
├─ frontend/
├─ public/
│ ├─ dist/
| ├─ .htaccess
│ ├─ app.php
我正在嘗試將 Vue3 專案構建到my-app/public/dist/檔案夾中,我通過設定outDir為vite.config.js:
build: {
outDir: '../public/dist'
},
就像那個專案是在dist檔案夾中構建的,但是當我在瀏覽器中打開頁面源時,構建腳本的相對 URL 不正確:
<link rel="stylesheet" href="/assets/index.585a031a.css">
例如,而不是/assets/index.585a031a.css應該是/dist/assets/index.585a031a.css。因此,我添加了另一個 Vite 選項base:
base: '/dist/',
就像那樣,當我轉到頁面源時,一切正常,但問題是應用程式的 URL 從更改example.com為example.com/dist.
這是我的.htaccess檔案,但我認為它與 無關.htaccess,因為我在 Vue2 應用程式中使用默認的 Vue CLI 具有相同的設定(未使用 Vite):
# Disable directory listing
Options -Indexes
# Enable the rewrite engine
RewriteEngine On
# Sets the base URL for rewrites
RewriteBase /
# Access to domain root should serve dist folder
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /dist/$1 [L]
# If URL doesn't match any static assets it should serve dist folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !/api/*
RewriteRule . /dist/$1 [L]
# If URL contains api it should serve app.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} /api/*
RewriteRule .* app.php [QSA,L]
所以,主要問題是我如何仍然在public/dist檔案夾中構建應用程式并保留應用程式的 URLexample.com而不是example.com/dist?
uj5u.com熱心網友回復:
問題是您index.html被放置在dist檔案夾中。所以 URL 需要example.com/dist為您的index.html. 您可以手動將您的檔案夾移動index.html到該public檔案夾??以查看它是否可以與 URL 一起使用example.com。
解決方案:將您的配置更改為:
{
...
// base: '/dist/', remove base config
build: {
outDir: '../public', // this line place index.html in the public folder
assetsDir: './dist', // this line place your assets in the public/dist folder
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/467181.html
標籤:.htaccess Vuejs2 建造 Vuejs3 维特
