hearsayit / HearsayRequireJSBundle

RequireJS integration for Symfony2.
130 stars 55 forks source link

Fix r.js build profile generation #41

Closed matoilic closed 11 years ago

matoilic commented 11 years ago

There are currently two bugs in the build profile generator. First, all path definitions have double file endings (file.js.js). Second, the shim definition is an array instead of an object. This pull request fixes both issues.

ihortymoshenko commented 11 years ago

@matoilic, thanks for the contribution. I know about bug with shim and I'll fix it ASAP. As for double file extensions, I haven't seen it when I tested it. Can you describe more detail how to reproduce it? By the way, I think there is not the place for it. It should be in the bundle Dependency Injection extension class. Thanks!

matoilic commented 11 years ago

I didn't put the path correction in the HearsayRequireJSExtension class because then the ModuleFormulaLoader fails because it expects that the path has a proper file ending. It seems like r.js is adding an additional ending to all files, as it expects all paths to not have a file ending. That's the reason why I have adapted the RjsFilter.

My Requirejs configuration looks as follows:

hearsay_require_js:
  base_directory: '@MyAppFrontendBundle/Resources/public/js'

  optimizer:
    path: %kernel.root_dir%/Resources/scripts/r.js
    options:
      optimize: ''
      skipPragmas: false
      preserveLicenseComments: false

  paths:
    backbone:
      location: '@MyAppFrontendBundle/Resources/public/js/backbone'
    marionette:
      location: '@MyAppFrontendBundle/Resources/public/js/backbone.marionette'
    babysitter:
      location: '@MyAppFrontendBundle/Resources/public/js/backbone.babysitter'
    wreqr:
      location: '@MyAppFrontendBundle/Resources/public/js/backbone.wreqr'
    zepto:
      location: '@MyAppFrontendBundle/Resources/public/js/zepto'
    deferred:
      location: '@MyAppFrontendBundle/Resources/public/js/deferred'
    json2:
      location: '@MyAppFrontendBundle/Resources/public/js/json2'
    underscore:
      location: '@MyAppFrontendBundle/Resources/public/js/underscore'

  shim:
    zepto:
      exports: 'Zepto'
    underscore:
      exports: '_'
    deferred:
      exports: 'Deferred'
      deps:
        - zepto
    backbone:
      exports: 'Backbone'
      deps:
        - zepto
        - json2
        - underscore
    wreqr:
      exports: 'Backbone.Wreqr'
      deps:
        - backbone
    babysitter:
      exports: 'Backbone.ChildViewContainer'
      deps:
        - backbone
    marionette:
      exports: 'Backbone.Marionette'
      deps:
        - zepto
        - deferred
        - backbone
        - wreqr
        - babysitter

All files that are specified under paths have double file extensions when I try to generate the optimized versions with

php app/console assetic:dump -e prod

I'm using PHP 5.4.18, r.js 2.1.8 and Symfony 2.3.3 with the following dependencies

"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/doctrine-bundle": "1.2.*",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "2.3.*",
"symfony/swiftmailer-bundle": "2.3.*",
"symfony/monolog-bundle": "2.3.*",
"sensio/distribution-bundle": "2.3.*",
"sensio/framework-extra-bundle": "2.3.*",
"sensio/generator-bundle": "2.3.*",
"incenteev/composer-parameter-handler": "~2.0",
"doctrine/migrations": "dev-master",
"doctrine/doctrine-migrations-bundle": "dev-master",
"symfony/security": "2.3.*",
"jms/security-extra-bundle": "1.5.*",
"stp/redactor-bundle": "dev-master",
"jms/serializer": "dev-master",
"hearsay/require-js-bundle": "dev-master"