【问题标题】:bootstrap.css doesn't show up in the browserbootstrap.css 没有出现在浏览器中
【发布时间】:2025-12-25 19:00:17
【问题描述】:

我正在使用本教程设置一个 angular 2 和 gulp 的项目。 http://blog.codeleak.pl/2016/03/quickstart-angular2-with-typescript-and.html

我所做的唯一更改是将引导程序添加到 package.json,但它没有显示在浏览器中。它显示在我的 IDE 项目中的 node_modules 和 lib 文件夹中。但是如果我使用引导类,它们就不会被应用。 bootstrap.min.css 文件也不显示在浏览器中。

我在我的 gulp 文件中添加了关于引导程序的 2 行

gulp.task("libs", () => {
    return gulp.src([
        'es6-shim/es6-shim.min.js',
        'systemjs/dist/system-polyfills.js',
        'systemjs/dist/system.src.js',
        'reflect-metadata/Reflect.js',
        'rxjs/**',
        'zone.js/dist/**',
        '@angular/**',
        'bootstrap/dist/js/bootstrap.min.js',
        'bootstrap/dist/css/bootstrap.min.css'
    ], {cwd: "node_modules/**"}) /* Glob required here. */
    .pipe(gulp.dest("build/lib"));
});

我在 index.html 中添加了这一行以包含它

 <link rel="stylesheet" type="text/css" src="lib/bootstrap/dist/css/bootstrap.min.css">

这是我的项目结构

编辑:澄清一下,我看到 bootstrap.css 文件复制到 IDE 的 lib 文件夹中,但我在浏览器中看不到它。请参阅下面来自 Chrome 开发工具的屏幕截图

关于我可能缺少什么的任何线索? Github 仓库 - https://github.com/richa008/Angular-starter-app-with-gulp

【问题讨论】:

  • 您确定浏览器中是否加载了引导 css?如果您在浏览器控制台上看到任何错误怎么办?你是如何应用 css 类的?
  • 浏览器没有加载,就是这个问题。我不明白为什么它没有加载。我也没有在控制台中看到任何错误
  • 试试&lt;link rel="stylesheet" type="text/css" src="../lib/bootstrap/dist/css/bootstrap.min.css"&gt;&lt;link rel="stylesheet" type="text/css" src="bootstrap/dist/css/bootstrap.min.css"&gt;

标签: node.js twitter-bootstrap typescript angular gulp


【解决方案1】:

这应该导入所有相关的文件和目录:

    gulp.task("libs", () => {
        return gulp.src([
            'es6-shim/es6-shim.min.js',
            'systemjs/dist/system-polyfills.js',
            'systemjs/dist/system.src.js',
            'reflect-metadata/Reflect.js',
            'rxjs/**',
            'zone.js/dist/**',
            '@angular/**',
            'bootstrap/dist/**/*.+(js|css.map|css|eot|svg|ttf|woff|woff2)'

        ], { cwd: "node_modules/**" }) /* Glob required here. */
            .pipe(gulp.dest("build/lib"));
    });

【讨论】:

  • 这确实导入了文件夹中的所有引导文件,我可以在 IDE 中看到它们。但它们仍然不会在浏览器中加载
最近更新 更多