1

I am trying to create a requirejs optimization config with grunt and almond. Here's the config:

requirejs:
      build:
        options:
          almond: true
          dir: 'build'
          appDir: ''
          baseUrl: '../client'
          wrap: true
          include: '../client/main'
          keepBuildDir: true
          paths:
            underscore: 'client/vendor/underscore'
            jquery    : 'client/vendor/jquery'
            backbone  : 'client/vendor/backbone'

Folder Structure:

enter image description here

Error:

C:\Users\User\Documents\Source\Project>grunt requirejs
Running "requirejs:build" (requirejs) task
>> Error: ENOENT, no such file or directory
>> 'C:\Users\User\Documents\Source\Project\build\models\MenuItem.js'
>> In module tree:
>>     ../client/main
Warning: RequireJS failed. Use --force to continue.

Main.js code (written in coffeescript)

requirejs.config(
  baseUrl: "client"
  shim:
    'backbone':
      deps: ['jquery']
      exports: 'Backbone'
    'jquery':
      exports: '$'
    'underscore':
      exports: '_'
  paths:
    jquery: 'vendor/jquery-1.11.0'
    underscore: 'vendor/underscore'
    backbone: 'vendor/backbone'
)

define 'start', ()->
  window.types =
    Models: {}
    Collections: {}
    Views: {}
  null

require ['models/MenuItem', 'views/MenuItem'], (MenuItemModel, MenuItemView)->
  view = new MenuItemView(
    new MenuItemModel(),
    "#app",
    'first'
  )
  view.render();
  null

I want to compile my entire project spread across multiple js files into a single file in a way that requirejs would not be needed. I am trying to do this using almond js but the build task does not look for referenced files relative to the path of referring file. Please help me with the correct configuration.

EternallyCurious
  • 2,345
  • 7
  • 47
  • 78
  • could you please add main.js code? – Evgeniy Jul 01 '14 at 06:11
  • @Evgeniy. There you go! – EternallyCurious Jul 01 '14 at 07:27
  • try to add mainConfigFile: 'path/to/main.js' after baseUrl – Evgeniy Jul 01 '14 at 07:30
  • Just checking the obvious stuff... the error complains about build\models\MenuItem.js, but your screenshot shows build\views\MenuItem.js - is that right? Does the file from the error exist? – izb Jul 01 '14 at 07:33
  • @izb Yes the file exists: There's MenuItem.js in models that I have not expanded in the image. – EternallyCurious Jul 01 '14 at 09:05
  • @Evgeniy I added `mainConfigFile: 'client/main.js'`: which produces the exact same error shown above. The mainConfigFile parameter does not seem relative the baseUrl. I'm not sure what the filePaths in the config are supposed to be relative to. There are many parameters like `baseUrl`, `appDir` and `dir` in the requirejs configuration – EternallyCurious Jul 01 '14 at 09:09

0 Answers0