metalsmith-browser-sync icon indicating copy to clipboard operation
metalsmith-browser-sync copied to clipboard

How to inject CSS without reload? What am I doing wrong?

Open jamiewilson opened this issue 10 years ago • 5 comments

Here's my metalsmith pipeline:

metalsmith(__dirname)
  .use(markdown())
  .use(prism())
  .use(metadata())
  .use(permalinks())
  .use(inplace())
  .use(layouts())
  .use(assets())
  .use(sass())
  .use(prefix())
  .use(uglify())
  .use(browsersync(files: [
    "layouts/**/*",
    "pages/**/*",
    "assets/**/*"
  ]))
  .build();

Any ideas? Do I need to be running browsersync in a separate pipeline branch or something?

Also, I'm not getting any file change logs, just the reload:

screen shot 2015-11-13 at 11 47 52 am

jamiewilson avatar Nov 13 '15 17:11 jamiewilson

Hey @mdvorscak, did you perhaps get a chance to consider this question yet? I'm stuck :/

jamiewilson avatar Dec 08 '15 22:12 jamiewilson

Does your index.html file have a <body> tag? https://browsersync.io/docs/#requirements

mhkeller avatar Jan 13 '16 04:01 mhkeller

@mhkeller thanks for suggestion! I do have body tags in my index, and I also tried moving around some of my handlebars templates to double check and am pretty sure that's not the issue. I'm getting a the full reload, which if I recall from other projects, would break without the

tag.

jamiewilson avatar Jan 13 '16 15:01 jamiewilson

Hi @jamiewilson did you fix your issue ? I'm having exactly the same problem. Thank you

smontlouis avatar Jul 26 '16 20:07 smontlouis

I just quickly added this to index.js line 27 to fix

        function rebuild(event, file) {
            if (!bs.paused) {
                bs.pause();

                metalsmith.build(function(err) {
                    var buildMessage = err ? err : 'Build successful';
                    debug(buildMessage);
                    
                    bs.resume();

                    if (require('path').extname(file) === '.scss') {
                      bs.reload('*.css');
                    } else {
                      bs.reload();
                    }
                });
            }
        }

a-axton avatar Feb 15 '17 20:02 a-axton