我撰寫了一個 Web 應用程式,我使用 yarn 來管理 CSS 和 JavaScript 依賴項。我決定開始使用我在 package.json 檔案中作為開發依賴項添加的 parcel、sass、typescript 等工具。
package.json 檔案位于根檔案夾中,但我的 yarn 安裝依賴項位于 /public/vendor/ 檔案夾中,因為用戶無法直接訪問 /public/ 檔案夾之外的任何內容。所以我無法將 /node_modules/ 檔案夾中的庫鏈接到我的 HTML。
這是我的 /.yarnrc 檔案的內容:
--modules-folder ./public/vendor --ignore-optional --production=true
問題是即使 yarn 會創建自己的 yarn.lock 檔案,它也會考慮到 package-lock.json 檔案的內容。因此,如果 npm 已經安裝了依賴項,除非我明確宣告要安裝它(這意味著它適用于依賴項,但不適用于依賴項依賴項),否則 yarn 不會安裝它。
uj5u.com熱心網友回復:
使用兩個不同的包管理器是一個糟糕的設計理念。
相反,我編輯了我的 .htaccess 檔案,以便將路徑 /public/vendor 鏈接到 /node_modules 目錄:
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteCond %{REQUEST_URI}::$1 ^(/. )/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1,E=REL_URI:/%2]
RewriteCond %{ENV:REL_URI} ^/public/vendor/ [OR]
RewriteCond %{REQUEST_URI} ^/public/vendor/
RewriteCond %{REQUEST_URI} !.*\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule public/vendor/(.*)$ %{ENV:BASE}/node_modules/$1 [L]
RewriteCond %{ENV:REL_URI} ^/public/ [OR]
RewriteCond %{REQUEST_URI} ^/public/
RewriteCond %{REQUEST_URI} !.*\.php
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/index.php [L]
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/435505.html
