2017 © Pedro Peláez
 

symfony-bundle requirejs-bundle

BAP RequireJS Bundle

image

oro/requirejs-bundle

BAP RequireJS Bundle

  • Tuesday, May 15, 2018
  • by dmitriysoroka
  • Repository
  • 13 Watchers
  • 1 Stars
  • 34 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 17 Versions
  • 0 % Grown

The README.md

OroRequireJSBundle

OroRequireJSBundle uses the RequireJS library to enable a modular structure of JS components in Oro applications., (*1)

The bundle enables developers to define RequireJS configuration in YAML files on the bundle level. It also provides a CLI tool to collect RequireJS modules and configuration from bundles, merge and minify them in the production mode., (*2)

For details of the RequireJS configuration options, see RequireJS API. For details of the RequireJS build options, see example.build.js., (*3)

Require.js config generation

Configuration

Common options for require.js config are placed in config.yml:, (*4)

oro_require_js:
    config: # common options which will eventually get into require.js config file
        waitSeconds: 0
        enforceDefine: true
        scriptType: 'text/javascript'

Bundle specific options are defined inside requirejs.yml file, which is placed in %BundleName%\Resources\config\requirejs.yml. It can have three sections shim, map and paths (see RequireJS API). Each bundle's javascript module have to be defined in paths section, where key is a module name and value is its relative path from the document root., (*5)

config:
    shim:
        'jquery-ui':
            deps:
                - 'jquery'
    map:
        '*':
            'jquery': 'oroui/js/jquery-extend'
        'oroui/js/jquery-extend':
            'jquery': 'jquery'
    paths:
        'jquery': 'bundles/oroui/lib/jquery-1.10.2.js'
        'jquery-ui': 'bundles/oroui/lib/jquery-ui.min.js'
        'oroui/js/jquery-extend': 'bundles/oroui/js/jquery-extend.js'

Generation

Main require.js config is generated automatically and embedded in HTML-page. The config is stored in application cache. In case you wish to renew require.js configuration, just clean cache., (*6)

Usage

To get require.js script with its configuration on your page, just include scripts.html.twig template from OroRequireJSBundle to <head/> tag of your index.html.twig template., (*7)

<head>
    <!-- -->
    {% include 'OroRequireJSBundle::scripts.html.twig' %}
    <!-- -->
</head>

The template scripts.html.twig accepts two optional parameters compressed and config_extend., (*8)

  • compressed is boolean (true by default), determines whether to use minified js-file or not. Usually it's opposite to app.dev flag.
  • config_extend is a string with javascript code, allows to extend requirejs configuration in runtime mode (see runtime require.js config)., (*9)

    {% set requirejs_config_extend %} // custom javascript code {% endset %} {% include 'OroRequireJSBundle::scripts.html.twig' with { compressed: not app.debug, config_extend: requirejs_config_extend } %}, (*10)

Runtime require.js main config extension

Sometimes it is not enough to specify require.js configuration settings statically, it is required to modify certain parameters dynamically at each launch. It is possible to do this over config_extend parameter for OroRequireJSBundle::scripts.html.twig template. That variable can contain a piece of custom configuration which will be applied after general configuration is loaded and before any module is utilized., (*11)

E.g. to dynamically define the path to translation dictionary (depending on what locale is currently used):, (*12)

{% set requirejs_config_extend %}
    require({
        paths: {
            'oro/translations':
                '{{ url('oro_translation_jstranslation')[0:-3] }}'
        }
    });
{% endset %}

In terms of sequence of code execution, it looks the following way:, (*13)

  1. Prod mode (and built resource exists)
    • execute all custom configurations
      require(/* ... */); require(/* ... */); require(/* ... */);
    • load single minified js-resource (with require-config.js + require.js and rest of modules)
  2. Dev mode (or built resource does not exist)
    • load require.js
    • load js/require-config.js
    • execute all custom configurations
      require(/* ... */); require(/* ... */); require(/* ... */);

See @OroRequireJSBundle::scripts.html.twig, (*14)

Build project

Configuration

Build configuration starts in config.yml, (*15)

oro_require_js:
    build_path: "js/oro.min.js"     # relative path from document root folder to project built
    building_timeout: 3600
    js_engine: "node"               # can be configured to use other engine, e.g. Rhino
    build_logger: false             # show in browser console not optimized RequireJS modules 
    build:                          # build.js's common options
        optimize: "uglify2"
        preserveLicenseComments: true
        generateSourceMaps: true
        useSourceUrl: true

See details for oro_require_js.build options., (*16)

Beside general build-configuration, you can set bundle specific options inside %BundleName%\Resources\config\requirejs.yml file, root section build., (*17)

build:
    paths:
        'autobahn': 'empty:'

This directive will prevent module from getting concatenated into build file., (*18)

Building

To make a build for JS-resources, just execute a command in console:, (*19)

php bin/console oro:requirejs:build

It will:, (*20)

  1. take initial configuration from oro_require_js.build (config.yml);
  2. extend it with configuration found in bundles (%BundleName%\Resources\config\requirejs.yml);
  3. generate build.js - a config for builder;
  4. run builder (time consuming process, especially for Rhino JS-engine);
  5. remove build.js.

The Versions

15/05 2018

dev-master

9999999-dev https://github.com/orocrm/RequireJSBundle

BAP RequireJS Bundle

  Sources   Download

MIT

The Requires

 

requirejs bap

14/08 2014

1.3.1

1.3.1.0 https://github.com/laboro/RequireJSBundle

BAP RequireJS Bundle

  Sources   Download

MIT

The Requires

 

requirejs bap

01/08 2014

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/laboro/RequireJSBundle

BAP RequireJS Bundle

  Sources   Download

MIT

The Requires

 

requirejs bap

23/06 2014

1.3.0

1.3.0.0 https://github.com/laboro/RequireJSBundle

BAP RequireJS Bundle

  Sources   Download

MIT

The Requires

 

requirejs bap

19/05 2014

1.2.0

1.2.0.0 https://github.com/laboro/RequireJSBundle

BAP RequireJS Bundle

  Sources   Download

MIT

The Requires

 

requirejs bap

10/04 2014

1.0.1

1.0.1.0 https://github.com/laboro/RequireJSBundle

BAP RequireJS Bundle

  Sources   Download

MIT

The Requires

 

requirejs bap

10/04 2014

1.1.0

1.1.0.0 https://github.com/laboro/RequireJSBundle

BAP RequireJS Bundle

  Sources   Download

MIT

The Requires

 

requirejs bap

10/04 2014

1.1.1

1.1.1.0 https://github.com/laboro/RequireJSBundle

BAP RequireJS Bundle

  Sources   Download

MIT

The Requires

 

requirejs bap

10/04 2014

1.2.0-rc1

1.2.0.0-RC1 https://github.com/laboro/RequireJSBundle

BAP RequireJS Bundle

  Sources   Download

MIT

The Requires

 

requirejs bap

04/03 2014

1.0.0

1.0.0.0 https://github.com/laboro/RequireJSBundle

BAP RequireJS Bundle

  Sources   Download

MIT

The Requires

 

requirejs bap

29/12 2013

1.0.0-rc2

1.0.0.0-RC2 https://github.com/laboro/RequireJSBundle

BAP RequireJS Bundle

  Sources   Download

MIT

The Requires

 

requirejs bap

29/12 2013

1.0.0-rc3

1.0.0.0-RC3 https://github.com/laboro/RequireJSBundle

BAP RequireJS Bundle

  Sources   Download

MIT

The Requires

 

requirejs bap

05/12 2013

1.0.0-rc1

1.0.0.0-RC1 https://github.com/laboro/RequireJSBundle

BAP RequireJS Bundle

  Sources   Download

MIT

The Requires

 

requirejs bap

03/12 2013

1.0.0-beta5

1.0.0.0-beta5 https://github.com/laboro/RequireJSBundle

BAP RequireJS Bundle

  Sources   Download

MIT

The Requires

 

requirejs bap

04/11 2013

1.0.0-beta4

1.0.0.0-beta4 https://github.com/laboro/RequireJSBundle

BAP RequireJS Bundle

  Sources   Download

MIT

The Requires

 

requirejs bap

30/10 2013

1.0.0-beta3

1.0.0.0-beta3 https://github.com/laboro/RequireJSBundle

BAP RequireJS Bundle

  Sources   Download

MIT

The Requires

 

requirejs bap

21/10 2013

1.0.0-beta2

1.0.0.0-beta2 https://github.com/laboro/RequireJSBundle

BAP RequireJS Bundle

  Sources   Download

MIT

The Requires

 

requirejs bap