2017 © Pedro Peláez
 

symfony-bundle require-js-bundle

This bundle provides integration of the RequireJS library into Symfony2

image

instaclick/require-js-bundle

This bundle provides integration of the RequireJS library into Symfony2

  • Wednesday, November 20, 2013
  • by heldr
  • Repository
  • 16 Watchers
  • 0 Stars
  • 6 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 64 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

HearsayRequireJSBundle

Overview

This bundle provides integration of the RequireJS library into Symfony2., (*1)

Installation

To install HearsayRequireJSBundle with Composer just add the following to your composer.json file:, (*2)

{
    // ...
    "require": {
        // ...
        "hearsay/require-js-bundle": "2.0.*@dev"
        // ...
    }
    // ...
}

Note that the master branch is under development and unstable yet. If you want to use stable version then specify the 1.0.* version. However, remember that the 1.0 branch no longer provides new features, only bug fixes., (*3)

Then, you can install the new dependencies by running Composer's update command from the directory where your composer.json file is located:, (*4)

$ php composer.phar update hearsay/require-js-bundle

Now, Composer will automatically download all required files, and install them for you. All that is left to do is to update your AppKernel.php file, and register the new bundle:, (*5)

<?php
// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new Hearsay\RequireJSBundle\HearsayRequireJSBundle(),
    // ...
);

Configuration

This bundle configured under the hearsay_require_js key in your application configuration. This includes settings related to paths, shim, optimization, and more., (*6)

require_js_src

type: string default: //cdnjs.cloudflare.com/ajax/libs/require.js/2.1.8/require.min.js, (*7)

This is a string that represents the template name which will render the RequireJS src or an URL to the RequireJS., (*8)

initialize_template

type: string default: HearsayRequireJSBundle::initialize.html.twig, (*9)

This is a string that represents the template name which will render the RequireJS initialization output. You can pass into this template any extra options., (*10)

base_url

type: string default: js required, (*11)

This is a string that represents the base URL where assets are served, relative to the website root directory. This URL also will exposed as an empty namespace., (*12)

base_dir

type: string default: null, (*13)

This is a string that represents the base URL for the r.js optimizer, that is generally actually a filesystem path., (*14)

paths

type: array default: null, (*15)

This is a prototype that represents an array of paths. Each path:, (*16)

  • includes the location and the key that determines whether the path is an external;
  • the location can be a string as well as an array of values (paths fallbacks);
  • the location can expose a file as well as a directory, if the location is a file then MUST NOT ends with the .js file extension;
  • the location can referred to the files using a path like @AcmeDemoBundle/Resources/public/js/src/modules;
  • by default, is not an external;
  • if specified as an external, will marked as an empty for the r.js optimizer;
  • will exposed as a namespace.

shim

type: array default: null, (*17)

This is a prototype that represents an array of shim, corresponds to the RequireJS shim config., (*18)

options

type: array default: null, (*19)

An array of key-value pairs to pass to the RequireJS. The value can have variable type., (*20)

optimizer

type: array default: null, (*21)

This block includes the r.js optimizer configuration options., (*22)

path

type: string default: null, (*23)

This is a string that represents the path to the r.js optimizer., (*24)

hide_unoptimized_assets

type: boolean default: false, (*25)

This determines whether the r.js optimizer should suppress unoptimized files., (*26)

exclude

type: array default: [], (*27)

An array of module names to exclude from the build profile., (*28)

options

type: array default: null, (*29)

An array of key-value pairs to pass to the r.js optimizer. The value can have variable type., (*30)

timeout

type: integer default: 60, (*31)

This determines the node.js process timeout, in seconds., (*32)

Full Default Configuration

hearsay_require_js:
    require_js_src:      //cdnjs.cloudflare.com/ajax/libs/require.js/2.1.8/require.min.js
    initialize_template: HearsayRequireJSBundle::initialize.html.twig
    base_url:            js
    base_dir:            ~ # Required
    paths:
        # Prototype
        path:
            location: ~ # Required
            external: false
    shim:
        # Prototype
        name:
            deps:    []
            exports: ~
    options:
        # Prototype
        name:
            value: ~ # Required
    optimizer:
        path:                    ~ # Required
        hide_unoptimized_assets: false
        exclude:                 []
        options:
            # Prototype
            name:
                value: ~ # Required
        timeout: 60

Usage

Just output the RequireJS initialization and load files normally:, (*33)

{{ require_js_initialize() }}


Alternately, you can specify a file to be required immediately via the data-main attribute:, (*34)

{{ require_js_initialize({ 'main' : 'demo/main' }) }}

If you need to do anything fancy with the configuration, you can do so manually by modifying the default configuration, and suppressing config output when initializing RequireJS:, (*35)



{{ require_js_initialize({ 'configure' : false }) }}

To make global changes to the configuration/initialization output, you can specify an initialization template in your configuration:, (*36)

# app/config/config.yml
hearsay_require_js:
    initialize_template: ::initialize_require_js.html.twig

To use this bundle with CoffeeScript, you can specify a path that contains .coffee scripts (means a directory). The scripts will renamed to .js scripts., (*37)

Note that the r.js optimizer cannot optimize .coffee scripts. However, you can apply the [Assetic][7] filter to this scripts by the file extension., (*38)

Optimization

This bundle provides the Assetic filter to create minified Javascript files using by r.js optimizer. This also inlines any module definitions required by the file being optimized. You need to provide a path to the r.js optimizer in your configuration to use the filter:, (*39)

# app/config/config.yml
hearsay_require_js:
    optimizer:
        path: %kernel.root_dir%/../r.js

You can then use it like any other filter; for example, to optimize only in production:, (*40)

{% javascripts
    filter='?requirejs'
    '@AcmeDemoBundle/Resources/public/js/src/main.js'
%}
    {{ require_js_initialize({ 'main' : asset_url }) }}
{% endjavascripts %}

Note that your configured path definitions will be incorporated into the optimizer filter, including the exclusion of external dependencies from the built profile's file., (*41)

If you wish to prevent unoptimized assets from being served (in e.g. production), you can suppress them:, (*42)

# app/config/config.yml
hearsay_require_js:
    optimizer:
        path: %kernel.root_dir%/../r.js
        hide_unoptimized_assets: true

If you're doing this, be sure that all the modules you need are bundled into your optimized assets (i.e. you're not accessing any modules by dynamic name, or if you are, then you're explicitly including those modules via optimizer options), otherwise you may see certain assets available in development, but not in production., (*43)

License

This bundle is released under the MIT license. See the complete license in the bundle:, (*44)

Resources/meta/LICENSE

The Versions

20/11 2013

dev-master

9999999-dev

This bundle provides integration of the RequireJS library into Symfony2

  Sources   Download

MIT

The Requires

 

by Kevin Montag

requirejs amd commonjs rjs

20/11 2013

v1.0.7

1.0.7.0

This bundle provides integration of the RequireJS library into Symfony2

  Sources   Download

MIT

The Requires

 

by Kevin Montag

requirejs amd commonjs rjs

04/04 2012

v0.1.0

0.1.0.0

Hearsay RequireJS Bundle

  Sources   Download

MIT

The Requires

 

by Kevin Montag

javascript requirejs require