无法使用Node-sass加载引导程序,bootstrap-sass

时间:2016-01-14 11:42:43

标签: css node.js twitter-bootstrap

我在基于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设置引导程序非常简单。如果您需要有关该项目的其他文件/信息,请与我们联系。

谢谢你的帮助!

2 个答案:

答案 0 :(得分:8)

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";

答案 1 :(得分:3)

在angular and gulp-sass中导入bootstrap-sass时遇到了类似的问题。在我的项目问题解决

li:nth-child(3n+1)