Problems This Helps With
- You're using requireJS and need to update the location of your modules after they have become minified and hashed.
- You're using requireJS and need to get the url of a particular file to add as the
data-mainattribute of your script reference.
npm install connect-assets-jspaths
- Note, there is a dependency on CoffeeScript.
Server Side Usage
assets = require "connect-assets" jsPaths = require "connect-assets-jspaths" # Snip ... app.use assets() # Exports the global function exportPaths() and jsUrl(); see below in View Helpers. jsPaths assets # Optionally, pass a log function to see progress # jsPaths assets, console.log
This module exports two global functions
Dynamic RequireJS Paths
Now that we have a variable with our requireJS friendly paths in it, we can set those paths in the RequireJS config
# Example main.coffee file in /assets/js folder requirePaths = paths: jquery: "//cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min" underscore: "//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min" backbone: "//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min" text: "/js/lib/text" handlebars: "/js/lib/handlebars" if jsPaths for own key, value of jsPaths # Fix up the lib references key = key.slice 4 if key.slice(0, 4) == "lib/" requirePaths.paths[key] = value require.config paths: requirePaths.paths shim: jquery: exports: "$" underscore: exports: "_" backbone: deps: ["underscore", "jquery"] exports: "Backbone" require ['app'], (App) -> new App().initialize()
Created by Jacob Gable. MIT License; no attribution required.