Git Product home page Git Product logo

Comments (3)

am11 avatar am11 commented on August 17, 2024

We do not cache the stylesheet results at all, but instead rely on 'modified timestamp' of .css vs. .scss/.sass.

We definitely compile if either of following conditions are met:

  • options.force is set
  • the target CSS does not exist
  • the target CSS exists, and sass_source_modified_time > css_target_modified_time, then recompile

Otherwise (after asserting all the implementation details), we skip the compilation step and simply invoke the caller's next middleware -- which in most cases is either (postcss-based) minifier or static files middleware.

from node-sass-middleware.

MentalGear avatar MentalGear commented on August 17, 2024

Mh... and the sass timestamp is copied right over from the original css file ?
Otherwise I would assume the sass timestamp could always differ because of the time it takes for the file to be converted.

Also, I noticed that the middleware seems to check any html files for external files ( in debug mode .js and .jpg files also pop up ), and then look into those folders, which I find somewhat peculiar.

For example, given the following folder structure
/stylesheets
--- /sass
--- /compiled_css/
----/third_party_library_css

Yet, when set to
sassMiddleware({
/* Options */
root: __dirname + "/public/stylesheets",
src: "/sass",
dest: "/css_compiled",

I still see in the debug that the sassMiddleware is looking for files like "selectbox.js.min" to convert, even though those are, besides scripts, not even in the src folder.
Shouldn't the library be only looking in the source folder, instead of into all the paths defined in all html files?

Also, is there a way to skip all files but sass files ?

from node-sass-middleware.

am11 avatar am11 commented on August 17, 2024

sass timestamp is copied right over from the original css file ?

The modified timestamp is set by OS when user or application modifies some file, we read the file metadata via node.js standard file-system API (mtime in fstat object: https://nodejs.org/api/fs.html#fs_class_fs_stats).

the debug that the sassMiddleware is looking for files like "selectbox.js.min" to convert

Nope, in debug, we just log a message that our middleware has 'seen' this request, but skip to the next() one right away, if the requested asset is a non-css file.

Also, is there a way to skip all files but sass files?

The concept of middleware is that the server (express.js et al.) passes through the request to the middleware chain; the first middleware calls the second one, second calls the third and so on. If some middleware wants to handle the request, it will do so and either:

  • pass the control to the next one by calling next() function injected by the server app
  • respond success (200) or error (404 etc.) and terminate the middleware pipe.

The middleware is configured by the consumer and next() follows the order the user has specified:

e.g.

var server = require('express')();
var sassMiddleware = require('node-sass-middleware');
var postcssMiddleware = require('postcss-middleware');

server
  .use ( sassMiddleware ( sassMiddlewareOptions ) )        // this middleware will be called first
  .use ( postcssMiddleware ( postcssMiddlewareOptions ) )  // this will be called when previous
                                                           // one invokes next()
/* and so on */
  ;

from node-sass-middleware.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.