[英]Unable to load bootstrap with Node-sass, bootstrap-sass
我正在使用基于node / express的旧/新项目,其中boostrap源被痛苦地复制粘贴(并且被黑客入侵)。 我想使用bootstrap包更易于维护。 但是,在添加bootstrap-sass和node-sass之后,我遇到了这个错误:
这是错误
in /vagrant/sass/theme.scss:28:1
Error: File to import not found or unreadable: bootstrap/variables
Parent style sheet: /vagrant/sass/theme.scss
at options.error (/vagrant/node_modules/node-sass/lib/index.js:277:32)
source: /vagrant/sass/vendor/bootstrap-datepicker/css/bootstrap-datepicker3.min.scss
dest: /vagrant/public/css/vendor/bootstrap-datepicker/css/bootstrap-datepicker3.min.css
read: /vagrant/public/css/vendor/bootstrap-datepicker/css/bootstrap-datepicker3.min.css
source: /vagrant/sass/theme.scss
dest: /vagrant/public/css/theme.css
read: /vagrant/public/css/theme.css
error: File to import not found or unreadable: bootstrap/variables
Parent style sheet: /vagrant/sass/theme.scss
in /vagrant/sass/theme.scss:28:1
Error: File to import not found or unreadable: bootstrap/variables
Parent style sheet: /vagrant/sass/theme.scss
at options.error (/vagrant/node_modules/node-sass/lib/index.js:277:32)
server.js
app.use(
sass({
src: __dirname + '/sass',
dest: __dirname + '/public/css',
prefix: '/css',
// outputStyle: 'compressed',
debug: true,
})
);
的package.json:
"dependencies": {
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.13.1",
"bootstrap-sass": "^3.3.6",
"connect-flash": "^0.1.1",
"cookie-parser": "^1.3.5",
"express": "^4.12.4",
"express-session": "^1.11.3",
"mysql": "^2.7.0",
"node-sass": "^3.4.2",
"node-sass-middleware": "^0.9.7",
"passport": "^0.2.2",
"passport-facebook": "^2.0.0",
"passport-google-oauth": "^0.2.0",
"passport-local": "^1.0.0",
"passport-twitter": "^1.0.3",
"randomstring": "^1.1.3",
"sendgrid": "^1.9.2",
"sequelize": "^3.9.0",
"sequelize-fixtures": "^0.4.8",
"shelljs": "^0.5.3",
"swig": "^1.4.2"
},
"devDependencies": {
"eslint": "^1.10.3",
"gulp": "^3.9.0",
"gulp-zip": "^3.0.2",
"jake": "^8.0.12",
"minimist": "^1.2.0",
"node-sass": "^3.3.3",
"node-sass-middleware": "^0.9.6"
}
theme.scss
/*!
* Bootstrap v3.3.6 (http://getbootstrap.com)
* Copyright 2011-2015 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
// Core variables and mixins
@import "bootstrap/variables";
@import "bootstrap/mixins";
// Reset and dependencies
@import "bootstrap/normalize";
@import "bootstrap/print";
@import "bootstrap/glyphicons";
// Core CSS
@import "bootstrap/scaffolding";
@import "bootstrap/type";
@import "bootstrap/code";
@import "bootstrap/grid";
@import "bootstrap/tables";
@import "bootstrap/forms";
@import "bootstrap/buttons";
// Components
@import "bootstrap/component-animations";
@import "bootstrap/dropdowns";
@import "bootstrap/button-groups";
@import "bootstrap/input-groups";
@import "bootstrap/navs";
@import "bootstrap/navbar";
@import "bootstrap/breadcrumbs";
@import "bootstrap/pagination";
@import "bootstrap/pager";
@import "bootstrap/labels";
@import "bootstrap/badges";
@import "bootstrap/jumbotron";
@import "bootstrap/thumbnails";
@import "bootstrap/alerts";
@import "bootstrap/progress-bars";
@import "bootstrap/media";
@import "bootstrap/list-group";
@import "bootstrap/panels";
@import "bootstrap/responsive-embed";
@import "bootstrap/wells";
@import "bootstrap/close";
// Components w/ JavaScript
@import "bootstrap/modals";
@import "bootstrap/tooltip";
@import "bootstrap/popovers";
@import "bootstrap/carousel";
// Utility classes
@import "bootstrap/utilities";
@import "bootstrap/responsive-utilities";
我是节点的新手,来自Rails,使用sass设置bootstrap非常简单。 如果您需要有关该项目的其他文件/信息,请告诉我们。
谢谢你的帮助!
将bootstrap-sass
导入到React / Webpack项目时,我遇到了类似的问题,但解决方案是相同的。 在主scss文件(theme.scss)中,您需要通过node_modules包中的相对路径减去node_modules
路径段来@import个别mixins。
如果要提取单个功能,则需要更改@import "bootstrap/feature"
路径,以反映要在bootstrap-sass程序包中使用的每个功能的路径。 另请注意路径中的前面的~
,它解决了导航到SCSS文件的错误。
@import "~bootstrap-sass/assets/stylesheets/bootstrap/variables";
另一个问题是,如果您要使用字形图,则需要将$icon-font-path
为指向包中的fonts文件夹,否则服务器将错误地找到这些文件。
$icon-font-path: "~bootstrap-sass/assets/fonts/bootstrap/";
@import "bootstrap-sass/assets/stylesheets/bootstrap/glyphicons";
如果你只想使用包中的所有东西,你可以设置icon-font-path并在theme.scss文件中拉入所有样式。
// Bootstrap
$icon-font-path: "~bootstrap-sass/assets/fonts/bootstrap/";
@import "~bootstrap-sass/assets/stylesheets/_bootstrap.scss";
我在angular and gulp-sass中导入bootstrap-sass时遇到了类似的问题。 在我的项目问题解决
"./node_modules/bootstrap-sass/assets/stylesheets/bootstrap/variables"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.