简体   繁体   English

CSS/JS 未链接到 HTML 页面

[英]CSS/JS not linking to HTML page

I have created setup using below tutorial: https://coursetro.com/posts/design/72/Installing-Bootstrap-4-Tutorial我使用以下教程创建了设置: https://coursetro.com/posts/design/72/Installing-Bootstrap-4-Tutorial

When I run gulp file CSS/JS are not linked, I have applied bg color on body but not applying on this.当我运行 gulp 文件 CSS/JS 未链接时,我在主体上应用了 bg 颜色,但未在此应用上。

I have installed bootstrap 4 using npm and add gulpfile to process, below code is for gulp file:我已经使用 npm 安装了引导程序 4,并添加了 gulpfile 来处理,以下代码用于 gulp 文件:

var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');

// Compile sass into CSS & auto-inject into browsers
gulp.task('sass', function() {
return gulp.src(['node_modules/bootstrap/scss/bootstrap.scss', 'src/scss/*.scss'])
.pipe(sass())
.pipe(gulp.dest("src/css"))
.pipe(browserSync.stream());
});

// Move the javascript files into our /src/js folder
gulp.task('js', function() {
return gulp.src(['node_modules/bootstrap/dist/js/bootstrap.min.js', 'node_modules/jquery/dist/jquery.min.js', 'node_modules/popper.js/dist/umd/popper.min.js'])
.pipe(gulp.dest("src/js"))
.pipe(browserSync.stream());
});

// Static Server + watching scss/html files
gulp.task('serve', gulp.series('sass', function() {

browserSync.init({
server: "./src"
});

gulp.watch(['node_modules/bootstrap/scss/bootstrap.scss', 'src/scss/*.scss'], gulp.series('sass'));
gulp.watch("src/*.html").on('change', browserSync.reload);
}));

gulp.task('watch', function() {
    gulp.watch(['node_modules/bootstrap/scss/bootstrap.scss', 'src/scss/*.scss'], gulp.series('sass'));
});

gulp.task("default", gulp.series(gulp.parallel("js", "serve", 'sass')));

Using above code, localhost index page opened but css/js not applying on page:使用上面的代码,localhost 索引页面打开,但 css/js 未在页面上应用:

CSS code: body {background-color: #70501f; CSS 代码:body {背景色:#70501f; } }

Showing error on console like:在控制台上显示错误,例如:

Refused to apply style from 'http://localhost:3000/src/css/bootstrap.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.拒绝应用来自 'http://localhost:3000/src/css/bootstrap.css' 的样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型,并且启用了严格的 MIME 检查。 (index):1 Refused to apply style from 'http://localhost:3000/src/css/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled. (index):1 拒绝应用来自 'http://localhost:3000/src/css/style.css' 的样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型,并且严格的 MIME 检查已启用。

CSS: CSS:

<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@100;300;400;500;700;900&display=swap" rel="stylesheet">
<link type="text/css" href="/src/css/bootstrap.css" rel="stylesheet">
<link type="text/css" href="/src/css/style.css" rel="stylesheet">

JS: JS:

<script type="text/javascript" src="/src/js/jquery.min.js"></script>
<script type="text/javascript" src="/src/js/bootstrap.js"></script>
<script type="text/javascript" src="/src/js/popper.min.js"></script>

I have uploaded my code at here, please help me: https://github.com/pradeepmpatel/bootstrap4tuts我已经在这里上传了我的代码,请帮助我: https://github.com/pradeepmpatel/bootstrap4tuts

Thanks PP谢谢PP

I think the MIME Type error could be due to the css path not being correct.我认为 MIME 类型错误可能是由于 css 路径不正确。 It's trying to serve up an error instead of the css file which is not matching the MIME type.它试图提供错误而不是与 MIME 类型不匹配的 css 文件。 recheck your CSS & JS paths, it could be./src or./node_modules.重新检查您的 CSS 和 JS 路径,它可能是./src 或./node_modules。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM