wilson428 / node-lessify

LESS precompiler plugin for Browserify v2
MIT License
24 stars 13 forks source link

when using watchify, imported '.less' file is not recompiled #18

Closed andrepadez closed 8 years ago

andrepadez commented 9 years ago

use case: I have a /global.less file that is being imported from several require('./styles.less'). If i use watchify, and change the contents of global.less, i trigger the compiling process but the css isn't updated with the changes. If i disable watchify, it all works correctly, but it takes too much time.

Is there a way to deal with this? How?

Thanks

wilson428 commented 9 years ago

Hmm, I don't use watchify much so I don't know off the top of my head. @davejohn, do you know?

davejohn commented 9 years ago

@andrepadez I use beefy to trigger the recompiling process on updates. Beefy searches for a local instance of watchify, then browserify. Does this help?

andrepadez commented 9 years ago

I will have to try it, @davejohn , maybe later this week. I stopped using lessify early, and made my own solution (which is still not working perfectly), mostly because of #17 .

Nieralyte commented 8 years ago

Same error happens to me when i use watchify via JS API (CLI is fine).

My entry.js:

'use strict'
require('./styles.less')

styles.less:

h1 {color: blue}

gulpfile.js:

'use strict'

var gulp = require('gulp')
var browserify = require('browserify')
var watchify = require('watchify')
var lessify = require('node-lessify')
var streamTo = require('vinyl-source-stream')

gulp.task('watch', function() {
  var bundler = watchify(
    browserify('./entry.js', watchify.args)
  )
    .on('update', function() {
      build(bundler)
    })

  return build(bundler)
})

function build(bundler) {
  return bundler
    .transform(lessify)
    .bundle()

    .on('error', function(err) {
      console.log(String(err))
      this.emit('end')
    })

    .pipe(streamTo('bundle.js'))
    .pipe(gulp.dest('.'))
}

error:

D:\docs\projects\_experiments\2015-10-22T01h51m53s_node-lessify-error-hunt-down>gulp watch
[02:03:42] Using gulpfile D:\docs\projects\_experiments\2015-10-22T01h51m53s_node-lessify-error-hunt-down\gulpfile.js
[02:03:42] Starting 'watch'...
[02:03:42] Finished 'watch' after 95 ms
Error: Missing closing ')', line 1, column 10: ",(function() { var head = document.getElementsByTagName('head')[0]; var style = document.createElement('style'); sty
le.type = 'text/css';var css = "h1{color:blue}";if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } h
ead.appendChild(style);}())," while parsing file: D:\docs\projects\_experiments\2015-10-22T01h51m53s_node-lessify-error-hunt-down\styles.less
D:\docs\projects\_experiments\2015-10-22T01h51m53s_node-lessify-error-hunt-down\node_modules\node-lessify\index.js:88
                        compiled = output.css;
                                         ^

TypeError: Cannot read property 'css' of undefined
    at D:\docs\projects\_experiments\2015-10-22T01h51m53s_node-lessify-error-hunt-down\node_modules\node-lessify\index.js:88:21
    at D:\docs\projects\_experiments\2015-10-22T01h51m53s_node-lessify-error-hunt-down\node_modules\less\lib\less\render.js:26:35
    at D:\docs\projects\_experiments\2015-10-22T01h51m53s_node-lessify-error-hunt-down\node_modules\less\lib\less\parse.js:62:33
    at Object.finish [as _finish] (D:\docs\projects\_experiments\2015-10-22T01h51m53s_node-lessify-error-hunt-down\node_modules\less\lib\less\parser\parser.js:180:2
8)
    at Object.ImportVisitor._onSequencerEmpty (D:\docs\projects\_experiments\2015-10-22T01h51m53s_node-lessify-error-hunt-down\node_modules\less\lib\less\visitors\i
mport-visitor.js:35:14)
    at ImportSequencer.tryRun (D:\docs\projects\_experiments\2015-10-22T01h51m53s_node-lessify-error-hunt-down\node_modules\less\lib\less\visitors\import-sequencer.
js:50:14)
    at Object.ImportVisitor.run (D:\docs\projects\_experiments\2015-10-22T01h51m53s_node-lessify-error-hunt-down\node_modules\less\lib\less\visitors\import-visitor.
js:29:25)
    at Object.Parser.parse (D:\docs\projects\_experiments\2015-10-22T01h51m53s_node-lessify-error-hunt-down\node_modules\less\lib\less\parser\parser.js:189:22)
    at Object.parse (D:\docs\projects\_experiments\2015-10-22T01h51m53s_node-lessify-error-hunt-down\node_modules\less\lib\less\parse.js:61:18)
    at Object.render (D:\docs\projects\_experiments\2015-10-22T01h51m53s_node-lessify-error-hunt-down\node_modules\less\lib\less\render.js:25:18)