使用组件构建过程复制文件不起作用

时间:2014-07-29 10:43:20

标签: javascript node.js component.io

我正在使用componentcomponent build来管理和构建我的前端依赖项。我有一个取自the examples的节点脚本,它构建了我的所有组件。但它不是复制我的文件。这是违规的部分(下面包括完整的代码):

build.files(tree)
  .use('files', build.plugins.copy())
  .use('fonts', build.plugins.copy())
  .use('images', build.plugins.copy())
  .end();

我认为它不起作用,因为示例中的任何地方都没有fs.writeFileSync()调用,但我不确定它是否需要它。根据示例,它应该复制我的component.json中列出的文件,如下所示:

{
  "name": "component"
  "images": [
    "logo.jpg"
  ]
}

但它没有将我的图像复制到build文件夹(我相信component.jsons或组件本身没有任何错误,我怀疑它是构建代码的东西)。这是完整的脚本:

/**
 * =============================================================================
 * Builder (https://github.com/component/builder2.js)
 * =============================================================================
 */

var fs = require('fs');
var resolve = require('component-resolver');
var build = require('component-builder');
var mkdirp = require('mkdirp');

var argv = require('minimist')(process.argv.slice(2), {boolean: true}); // parse argument options
var src = process.cwd() + '/' + argv.src;
var dest = process.cwd() + '/' + argv.dest;
var components = process.cwd() + '/' + argv.components;
var buildname = argv.buildname;
var dev = argv.dev || false;

// resolve the dependency tree
resolve(src, {
  install: true, // install the remote components locally
  development: dev, // whether to include development components
  out: components // folder to install components to
}, function (err, tree) {
  if (err) throw err;

  // create 'dest' path
  mkdirp(dest, function (err) {
    if (err) throw err;
  });

  // build `.js` files from components' `.scripts` field
  build.scripts(tree)
    .use('scripts', build.plugins.js())
    .end(function (err, string) {
      if (err) throw err;
      fs.writeFileSync(dest + '/' + buildname + '.js', string);
    });

  // build `.css` files from components' `.styles` field
  build.styles(tree)
    .use('styles', build.plugins.css())
    .end(function (err, string) {
      if (err) throw err;
      fs.writeFileSync(dest + '/' + buildname + '.css', string);
    });

  // copy other files to the build folder
  build.files(tree)
    .use('files', build.plugins.copy())
    .use('fonts', build.plugins.copy())
    .use('images', build.plugins.copy())
    .end(); // callback optional
})

1 个答案:

答案 0 :(得分:0)

对于有相同问题的任何人:.copy()插件默认构建到build文件夹(我没有注意到,因为我正在构建我的css和js到另一个文件夹) 。要将.copy()插件构建到另一个文件夹,请将其传递给另一个目标,如下所示:

var dest = 'name-of-folder-or-complete-path';

// copy other files
build.files(tree, {destination: dest})
  .use('files', build.plugins.copy())
  .use('fonts', build.plugins.copy())
  .use('images', build.plugins.copy())
  .end(); // callback optional