1

我正在尝试让 broccolijs 使用 broccoli-less 编译更少文件的目录。我已将“预处理”功能更改如下:

var compileLess = require('broccoli-less')
var pickFiles = require('broccoli-static-compiler')

function preprocess (tree) {
  tree = filterTemplates(tree, {
    extensions: ['hbs', 'handlebars'],
    compileFunction: 'Ember.Handlebars.compile'
  })
  tree = filterCoffeeScript(tree, {
    bare: true
  })
  tree = compileLess(tree, {
      compress: false,
  })
  return tree
}

在我的项目文件夹中,我有一个名为“less”的目录,我将其包含在 Brocfile.js 中:

var lessStyles = 'less'
lessStyles = pickFiles(lessStyles, {
  srcDir: '/',
  files: ['main.less'],
  destDir: 'appkit'
})
lessStyles = preprocess(lessStyles)

var sourceTrees = [app, styles, vendor, lessStyles]
if (env !== 'production') {
  sourceTrees.push(tests)
}

sourceTrees = sourceTrees.concat(findBowerTrees())

尝试构建此项目会产生错误:

$ broccoli serve
Serving on http://localhost:4200


path.js:360
        throw new TypeError('Arguments to path.join must be strings');
        ^
TypeError: Arguments to path.join must be strings
  at path.js:360:15
  at Array.filter (native)
  at Object.exports.join (path.js:358:36)
  at tryPathIndex (/home/kyrre/beekeeper-frontend/node_modules/broccoli-less/node_modules/less/lib/less/index.js:223:37)
  at callback.type (/home/kyrre/beekeeper-frontend/node_modules/broccoli-less/node_modules/less/lib/less/index.js:226:29)
  at Object.oncomplete (fs.js:107:15)
4

1 回答 1

1

Sounds like you're probably looking for broccoli-less-single instead of broccoli-less

From the README:

This plugin is designed to compile a single, primary input file into a single output file, with a tree of @importd dependencies. This differs from broccoli-less, which compiles each .less file individually into a .css file and doesn't support @imports or a single output file depending on multiple inputs.

As an aside, it looks like you're working with Ember.js -- if so, I would strongly recommend using ember-cli instead of rolling your own build pipeline. It easily supports less and provides lots of other features.

于 2014-10-09T03:24:40.433 回答