My last email assumes your RequireJS modules live in the /META-INF/modules/ dir and follow the same naming convention. If that's not the case then you can 'Alias' your module.
define(["highcharts"], function(highcharts) { ... } If 'highcharts' lives elsewhere I can re-route the call to "/META-INF/modules/highcharts" like this: @Contribute(ModuleManager.class) public static void configureHighchartModule(MappedConfiguration<String, Object> config, AssetSource assetSource) { // injecting "@Path("classpath:/") Resource context" gives a service // recursion error during tests - so we use AssetSource instead Resource classpath = assetSource.resourceForPath("classpath:/"); Resource highcharts = classpath.forFile("/META-INF/assets/highcharts-2.3.5/highcharts.js"); config.add("highcharts", new JavaScriptModuleConfiguration(highcharts).exports("Highcharts")); } Steve. On 27 January 2013 23:13, Steve Eynon <steve.ey...@alienfactory.co.uk> wrote: > Good questions - I had to work this out myself when moving to T5.4! > > Yes, I personally consider @Import'ing JS deprecated - though it is > still valid if you don't wish to use RequireJS. > > In your component put: > > JSONObject params = new JSONObject(); > jsSupport.require("alienfactory/stuff").with(params); > > then create the JS file: > /META-INF/modules/alienfactory/stuff.js > > define(["jquery", "t5/core/console", "bootstrap"], function($, console) { > return function(params) { > console.warn("jQuery version: " + $().jquery); > }; > }); > > The above will give you access to jQuery (assuming you've chosen it as > your SymbolConstants.JAVASCRIPT_INFRASTRUCTURE_PROVIDER), will also > inject the T5 logger and ensure the bootstrap module is loaded and > initialised before calling your function. > > If you want multiple functions, i.e. > > jsSupport.require("alienfactory/stuff").invoke("f2"); > > then your JS module looks more like: > > define(["jquery", "t5/core/console", "bootstrap"], function($, console) { > return { > f1: function() { .. } > f2: function() { .. } > }; > }); > > CoffeeScript, if you wanna get into it, makes everything look a lot neater! > > Steve. > -- > Steve Eynon > ------------------------------- > "If at first you don't succeed, > so much for skydiving!" > > > > On 27 January 2013 20:30, Lance Java <lance.j...@googlemail.com> wrote: >> I'm using the new 5.4-alpha-2 and I'm not 100% sure how I should be managing >> my javascript. I'm a require.js newbie and I've got a few questions: >> >> 1. Are @Import(library=x) and JavascriptSupport.importJavaScriptLibrary(x) >> now considered deprecated or are there still valid use cases? >> >> 2. What would a best-practice "hello world" component look like if it >> requires one of the existing modules (eg bootstrap.js) >> >> 3. What would a best-practice "hello world" component look like if it does >> not require any other modules. >> >> Thanks, >> Lance. >> >> >> >> -- >> View this message in context: >> http://tapestry.1045711.n5.nabble.com/5-4-Javascript-best-practices-tp5719568.html >> Sent from the Tapestry - User mailing list archive at Nabble.com. >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >> For additional commands, e-mail: users-h...@tapestry.apache.org >> --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org