2016-09-30 51 views
0

參考Purpose of installing bootstrap through npm?包括bootstrap.js和bootstrap.css科爾多瓦

我使用這裏的例子: 下載NPM後,添加以下行到我的index.html

<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.min.css"> 
    <script src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script> 

不幸,我的元素的風格沒有改變。

我在做cordova運行瀏覽器時遇到以下情況。

200 /index.html (gzip) 
    404 /node_modules/bootstrap/js/bootstrap.min.js 
    404 /node_modules/bootstrap/bootstrap.min.css 
    200 /css/index.css (gzip) 
    200 /cordova.js (gzip) 
    200 /img/logo.png 
    200 /js/index.js (gzip) 
    200 /cordova_plugins.js (gzip) 
    200 /plugins/cordova-plugin-device/www/device.js (gzip) 
    200 /plugins/cordova-plugin-device/src/browser/DeviceProxy.js (gzip) 
    200 /plugins/cordova-plugin-splashscreen/www/splashscreen.js (gzip) 
    200 /plugins/cordova-plugin-splashscreen/src/browser/SplashScreenProxy.js (gzip) 
    200 /plugins/cordova-plugin-statusbar/www/statusbar.js (gzip) 
    200 /plugins/ionic-plugin-keyboard/www/browser/keyboard.js 
    200 /plugins/cordova-plugin-statusbar/src/browser/StatusBarProxy.js (gzip) 
    200 /config.xml 
    404 /node_modules/bootstrap/bootstrap.min.css 
    304 /css/index.css 
+0

您無法提供位於文檔根文件夾上方的內容。您的整個服務器的硬盤驅動器必須向公衆開放才能工作。查看鏈接到的線程中的第二個答案(您需要設置靜態路由)。 –

+0

@ChrisG所以我使用grunt dist命令行編譯css和js文件並將文件夾移動到我的www文件夾中?是對的嗎? – Lawrence

+0

不,我指的是:http://stackoverflow.com/a/35580597/5734311您設置了靜態路由。這意味着您只需在HTML中鏈接'/ js/bootstrap.min.js',但是也可以通過express來查找node_modules文件夾中的文件。 –

回答

0

在您喜歡的編輯器中打開project_folder/platforms/browser/cordova/run。尋找

var server = cordovaServe(); // line 47 for me 

正下方的是,插入此:

var n_m = __dirname + '/../../../node_modules'; 
server.app.use('/js', cordovaServe.static(n_m + '/bootstrap/dist/js')); 
server.app.use('/css', cordovaServe.static(n_m + '/bootstrap/dist/css')); 

現在包括像這樣的文件:

<link rel="stylesheet" href="/css/bootstrap.min.css"> 
<script src="/js/bootstrap.min.js"></script> 

科爾多瓦/快遞現在看在node_modules文件夾,以便唯一你必須做的事情是使用npm update。請注意,此僅限適用於cordova run browser

+0

因此,我只需要將此解決方案複製到其他平臺以使其適用於它們呢? – Lawrence

+0

不適用於android和ios。代碼不同 – Lawrence

+0

正確,因此您可能確實需要將文件複製到您的www文件夾。 –