代码之家  ›  专栏  ›  技术社区  ›  Nabor

将Bootstrap4与gulp sass一起使用

  •  1
  • Nabor  · 技术社区  · 6 年前

    我已经使用node安装了引导和jquery。

    "devDependencies": {
      "babel-preset-es2015": "^6.24.1",
      "babel-register": "^6.26.0",
      "bootstrap": "^4.0.0",
      "del": "^3.0.0",
      "gulp": "^4.0.0",
      "gulp-sass": "^3.2.0",
      "jquery": "^3.3.1"
    }
    

    项目结构:

    project /
    ├── node_modules /
    ├── src /
    │   ├── scss /
    │   │   ├── _bootswatch.scss
    │   │   ├── _variables.scss
    │   │   ├── styles.scss
    

    样式。scss的此内容取自 example

    @import "variables";
    @import "bootswatch";
    @import "~bootstrap/scss/bootstrap";
    

    gulpfile。巴贝尔。js具有从scss构建css的功能:

    const extRes = () => {
        return gulp.src('src/scss/styles.scss')
            .pipe(sass())
            .pipe(gulp.dest('public/css'));
    };
    

    虽然PhpStorm没有抱怨它找不到 ~bootstrap/scss/bootstrap ,生成过程失败,因为gulp sass不在node\u模块中查找。

    messageOriginal: File to import not found or unreadable: ~bootstrap/scss/bootstrap.
    Parent style sheet: C:/Entwicklung/2018/project/src/scss/styles.scss
    relativePath: src\scss\styles.scss
    domainEmitter: [object Object]
    domain: [object Object]
    domainThrown: false
    

    我还尝试将includePaths用于gulp sass,但我找不到一种方法来指定它以使构建过程正常工作。

    谁来帮我一下。

    更新1:

    与此同时,我已经解决了这个问题,但PhpStorm现在抱怨它不知道引导。是否可以将这两种解决方案结合在一起?

    当前样式。SCS:

    @import "variables";
    //@import "~bootstrap/scss/bootstrap";
    //noinspection CssUnknownTarget
    @import "bootstrap";
    @import "bootswatch";
    

    当前gulpfile。巴贝尔。js公司:

    const extRes = () => {
        return gulp.src('src/scss/styles.scss')
            .pipe(sass({
                includePaths: ['node_modules/bootstrap/scss/'],
                outputStyle: 'expanded'
            }))
            .pipe(prefix('last 2 versions'))
            .pipe(gulp.dest('public/css'));
    };
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   lena    6 年前

    通常,您需要将配置的目录标记为 包含路径 ( node_modules/bootstrap/scss )作为 资源 根目录( 将目录标记为/资源根目录 )使这种进口发挥作用。但如果 node_modules 因为整个文件夹被排除,并且 package.json 添加到javascript库中,因此不能标记/取消标记为根。。。 您可以尝试以下操作:

    • 在里面 文件|设置|语言(&A);框架| JavaScript |库 ,禁用/删除 <project_name>/node_modules 图书馆

    • 在里面 项目 工具窗口,选择 node_modules/bootstrap ,则, 将目录标记为/未排除

    • 选择 node\u模块/引导程序/SCS 文件夹 将目录标记为/资源根目录

    enter image description here