How do you install SASS with Express?

后端 未结 4 1982
情深已故
情深已故 2020-12-04 18:18

I am creating a node.js app with Express and socket.io. I want to use SASS and I see there is a npm package for it, what I don\'t understand is how do I link between the SAS

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-04 18:58

    Here is a solution based on various sources including the threads/comments above:

    node:

    var connect = require('connect');
    var sass = require('node-sass');
    
    var srcPath = __dirname + '/sass';
    var destPath = __dirname + '/public/styles';
    
    var server = connect.createServer(
        sass.middleware({
            src: srcPath,
            dest: destPath,
            debug: true,
            outputStyle: 'expanded',
            prefix: '/styles'
        }),
        connect.static(__dirname + '/public')
    );
    

    html:

    
        
        
             
    etc
    

    file system:

    rootDirectory / server.js (this is the node app)

    rootDirectory / public / styles / (this is where the compiled scss files will appear)

    rootDirectory / sass / main.scss

    This works for me and I've forked the example at:

    node-sass-example

    here:

    node-sass-example using prefix

提交回复
热议问题