componentjs / builder2.js

builder for component
50 stars 20 forks source link

scripts builder throws errors on require local file #61

Closed wprater closed 10 years ago

wprater commented 10 years ago

If the local file does not match the required extensions, but does exists, an error is thrown.

index.js

module.exports = {
  template: require('./template.html')
};

will throw Error: could not resolve "./template.html" from "home"'s file "index.js"

jonathanong commented 10 years ago

uhhh that means that file is missing

wprater commented 10 years ago

it's not. that's why I reported the bug. works when not using a custom builder script.

Please excuse my brevity; message sent from a mobile device.

On May 29, 2014, at 19:27, Jonathan Ong notifications@github.com wrote:

uhhh that means that file is missing

— Reply to this email directly or view it on GitHub.

timaschew commented 10 years ago

We need some tools like jsfiddle for easy reproducing behaviour. There is already runnable.com but it's hard and buggy in the UI.

I can reproduce and confirm the error, but it failed to save/publish it on runnable.com

It works fine with component-build but with API usage it fails (used it like in the builder2.js readme).

@jonathanong how component.json's templates property works / is handled?

jonathanong commented 10 years ago

i have no idea what's going on here. you have to give me code examples. i'm just guessing you guys are using the JS API and not using the templates/string plugin.

timaschew commented 10 years ago

okay here is the code base: https://github.com/timaschew/component-experiments and here you can run it: http://services-be50a0ec-289b-4801-bdd3-add180d2c71b.runnable.com/static/term.html just cd component-experiments and then node bundle.js

jonathanong commented 10 years ago

yeah you're not using hte plugin

timaschew commented 10 years ago

@jonathanong sorry that was the wrong link, that was for the issue of bundler.js

here is the code, run node bin/build.js: http://services-da757766-30c5-4c0d-ba19-e1bbf13316b7.runnable.com/static/term.html and it uses the plugins and doesn't work!

var fs = require('fs');
var resolve = require('component-resolver');
var build = require('component-builder');
var BUILD_DIR = "custom-build";

// resolve the dependency tree
resolve(process.cwd(), {
  // install the remote components locally
  install: true,
  destination: BUILD_DIR
}, function (err, tree) {
  if (err) throw err;

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

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

  // only copy `images` to the build folder
  build.files(tree)
    .end(); // callback optional
})
jonathanong commented 10 years ago

You need to use the string plugin to require templates

timaschew commented 10 years ago

I tried to include string plugin in both scripts and files:

build.scripts(tree)
    .use('scripts', build.plugins.js(), build.plugins.string())

still the same error

kewah commented 10 years ago

You need to use string plugin on the templates field

build
    .use('scripts', Builder.plugins.js()
    .use('templates', Builder.plugins.string());
timaschew commented 10 years ago

@kewah thanks! @wprater that works the docs are a little bit hidden: https://github.com/component/builder2.js/blob/master/docs/scripts.md#string

in the readme there is only a link to the doc for the builder, to find the other docs the user need to browse the doc directory on his own, I found no link via the mark down pages, this affects also some other component repository, maybe we should make a note for the user?

wprater commented 10 years ago

@timaschew thanks for your due diligence! started to use another builder, but will try and switch back when I can ;)