Stylesheet not loaded because of MIME-type

前端 未结 30 2880
猫巷女王i
猫巷女王i 2020-11-22 07:29

I\'m working on a website that uses gulp to compile and browser sync to keep the browser synchronised with my changes.

The gulp task compiles everything

30条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 07:54

    I have had the same problem.

    If your project's structure is like the following tree:

    index.html
    assets
    |-styles
      |-custom-style.css
    server
      |- server.js
    

    I recommend to add the following piece of code in server.js:

    var path = require('path')
    var express = require('express')
    var app = express()
    
    app.use('/assets', express.static(path.join(__dirname, "../assets")));
    

    Note: Path is a built-in Node.js module, so it doesn't need to install this package via npm.

提交回复
热议问题