Skip to content

Laravel bundle for managing Requirejs in your application

Notifications You must be signed in to change notification settings

jgallred/requirejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

requirejs

Laravel bundle for managing Requirejs in your application

Installation

  1. Clone the repo into your Laravel bundles directory
  2. Copy the bundle's config/requirejs.php to your application's config directory
  3. Publish the bundle's assets with php artisan bundle:publish

Using the Optimizer Task

The requirejs::optimize task lets you run the r.js optimizer within the artisan command. You need to install node on your machine. Specify a build profile for your modules and set its location in requirejs.php. Then, from the command line, run php artisan requirejs::optimize.

Storing the build profile

As an option, you can store your project build configuration with your require configuration. This lets you share shim and path settings between the two. If you use the build_profile configuration, then the profile file will be created at the location specified in build_profile_path automatically when you run the optimize task.

Loading require.js into your views

Simply inserting the require.js script

<html>
  <head>
  ...
  </head>
  <body>
  ...
  {{ Requirejs::load_require() }}
  </body>
</html>

Inserting the require.js script with a main module

<html>
  <head>
  ...
  </head>
  <body>
  ...
  {{ Requirejs::load_require("js/app/main") }}
  </body>
</html>

Configuring require.js

Require gives you lots of configuration options. The documentation tells you that it can be loaded like this:

<script>
var require = {
  "baseUrl" : "js/app/"
  "paths" : {
    ...
  }
}
</script>

This bundle lets you centralize your configuration in your application/config/requirejs.php file and then load it into your views. Just be sure to call Requirejs::config() before Requirejs::load_require().

<?php
return array(
  ...
  "config" => array(
    "baseUrl" => "js/app/",
    "paths" => array(
      ...
    )
  )
)
<html>
  <head>
  ...
  </head>
  <body>
  ...
  {{ Requirejs::config() }}
  {{ Requirejs::load_require("js/app/main") }}
  </body>
</html>

Since you'll probably do this quite often, there's a method that can combine both calls.

<html>
  <head>
  ...
  </head>
  <body>
  ...
  {{ Requirejs::require_script_config("js/app/main") }}
  </body>
</html>

About

Laravel bundle for managing Requirejs in your application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published