StarterSquad / ngseed

167 stars 48 forks source link

Error in plugin 'gulp-requirejs' #25

Closed paulflo150 closed 10 years ago

paulflo150 commented 10 years ago

Hi, I am getting an error while building with gulp, is there something I am missing?

gulp Using gulpfile gulpfile.js Starting 'js'... 'js' errored after 11 ms Error in plugin 'gulp-requirejs' Only single file outputs are supported right now, please pass a valid output file name!

Thanks,

Maqsim commented 10 years ago

Hi @paulflo150 Have you installed npm packages via npm install?

paulflo150 commented 10 years ago

Hi Maqsim, yup I have, I will try to do a fresh install of everything and see if that solves it.

Also, thanks for the project, I was trying to figure out for a couple of days how to split the controllers. There no way to combine the index.js and module.js into one file is there?

I was trying something like the code below, but that did not seem to work define(['angular'], function(angular) { angular.module('app.controllers',[]); require(['ctrl1','ctrl2'], function() { }); });

and then in my controllers: define(['angular'], function(angular) { angular.module('app.controllers').controller(....); }

Thanks,

Maqsim commented 10 years ago

@paulflo150 Hello. ngseed uses a modular paradigm and module app.controllers does not follow by that idea. It's just a tip. Also we develop ngseed wiki docs now, but it's not done yet. Btw, you can read about modules in ngseed here

Anyway, I can answer your question. Each component (controller, directive, service, filter etc.) should be defined in own file.

For example: (but I strongly recommended read by link above first)

index.js contains paths to module's components

define([
  './controller1-ctrl', // apart from '.js'
  './controller2-ctrl'
], function () {});

controller1-ctrl.js and controller2-ctrl.js are defined below. -ctrl is a suffix, but controller1(not good example) is a controller name.

module.js defines the module in app

define([
  'angular',
], function (angular) {
  'use strict';

  return angular.module('app.controller', []);
});

then we have 2 controller, so we need 2 files named controller1-ctrl.js and controller2-ctrl.js.

controller1-ctrl.js

// You see, instead of hardcoded 'angular.module('app.controllers')' we have linked './module' where is the module definition
define(['./module'], function (module) {
  'use strict';

  module.controller('Conteroller1Ctrl', ['$scope', function ($scope) {
    $scope.foo = 4;
  }]);
});

controller2-ctrl.js

define(['./module'], function (module) {
  'use strict';

  module.controller('Conteroller2Ctrl', ['$scope', function ($scope) {
    $scope.bar = function (n) {
      return n * n;
    };
  }]);
});

BUT! Module that has 2 controllers inside is unuseful module. You need some states and templates.