You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Sanket Sharma <sa...@gmail.com> on 2014/06/18 02:25:04 UTC

RequireJS Shim and JavaScriptModuleConfiguration

Hi,

How do I convert a non AMD javascript module to work with require.js?

I did some investigate and it seems like shimming is the way to go.
I would like to take a javascript file ol.js and shim to to export 'ol'.
The file is located under modules and is packaged in META-INF/modules
directory in the standard tapestry way.

Reading source code and documentation seems to suggest it can be done in
the following way:

@Contribute(ModuleManager.class)
public static void setupOpenLayersConfiguration(
MappedConfiguration<String, Object> mappedConfiguration,
@Inject @Path("classpath:META-INF/modules/ol/ol.js") Resource ol) {
JavaScriptModuleConfiguration openLayers = new
JavaScriptModuleConfiguration(ol);
openLayers.exports("ol");
 mappedConfiguration
.add("ol", openLayers);
}

What is the correct syntax to refer to inject this file as a resource? The
above class path syntax seems to be failing.

Is there a pure Javascript way as well? Been trying to play with
config/shim blocks but couldn't get it working.

Any help would be appreciated.

Best Regards,
Sanket

Re: RequireJS Shim and JavaScriptModuleConfiguration

Posted by Sanket Sharma <sa...@gmail.com>.
*enlightenment*

:-)
On 18 Jun 2014 09:34, "Geoff Callender" <ge...@gmail.com>
wrote:

> Not a bug.
> If you put actual modules in resources/META-INF/modules/, then they work
> fine.
> Put non-modules in resources/META-INF/assets/ and make them available as
> modules as I showed below by contributing to ModuleManager.
>
> On 18 Jun 2014, at 5:27 pm, Sanket Sharma <sa...@gmail.com> wrote:
>
> > Okay, it works if I place my javascript under /META-INF/assets/js
> >
> > Bug? Or does everything have to be under assets? It doesn't seem to pick
> up
> > resources under META-INF/modules.
> >
> >
> > On Wed, Jun 18, 2014 at 9:11 AM, Sanket Sharma <sa...@gmail.com>
> > wrote:
> >
> >>
> >> Nope. Doesn't work. I have my javascript files in the project under
> >> resources resources/META-INF/modules/ol/ol.js
> >>
> >> Does it map the META-INF/modules to a virtual resource? In your code I'm
> >> as suing there is a folder under META-INF called assets/js?
> >>
> >> If I use @Path("/META-INF/modules/ol/ol.js") corresponding to my folder
> >> structure it fails with the error below:
> >> Unable to locate asset 'classpath:modules.gz/modules/ol/ol.js' (the file
> >> does not exist).
> >>
> >> In the deployed file, it seems all javascript files are gzipped under
> >> context-root/modules.gz And thats where its loading all the javascript
> from.
> >>
> >>
> >>
> >>
> >>
> >>
> >> On Wed, Jun 18, 2014 at 3:41 AM, Geoff Callender <
> >> geoff.callender.jumpstart@gmail.com> wrote:
> >>
> >>> Here's one that worked, producing a module called jquery-ui:
> >>>
> >>>    public static void
> >>> contributeModuleManager(MappedConfiguration<String, Object>
> configuration,
> >>>            @Path("/META-INF/assets/js/jquery-ui-1.9.1.js") Resource
> >>> jqueryUi) {
> >>>        configuration.add("jquery-ui", new
> >>> JavaScriptModuleConfiguration(jqueryUi));
> >>>    }
> >>>
> >>> HTH,
> >>>
> >>> Geoff
> >>>
> >>> On 18 Jun 2014, at 10:25 am, Sanket Sharma <sa...@gmail.com>
> >>> wrote:
> >>>
> >>>> Hi,
> >>>>
> >>>> How do I convert a non AMD javascript module to work with require.js?
> >>>>
> >>>> I did some investigate and it seems like shimming is the way to go.
> >>>> I would like to take a javascript file ol.js and shim to to export
> 'ol'.
> >>>> The file is located under modules and is packaged in META-INF/modules
> >>>> directory in the standard tapestry way.
> >>>>
> >>>> Reading source code and documentation seems to suggest it can be done
> in
> >>>> the following way:
> >>>>
> >>>> @Contribute(ModuleManager.class)
> >>>> public static void setupOpenLayersConfiguration(
> >>>> MappedConfiguration<String, Object> mappedConfiguration,
> >>>> @Inject @Path("classpath:META-INF/modules/ol/ol.js") Resource ol) {
> >>>> JavaScriptModuleConfiguration openLayers = new
> >>>> JavaScriptModuleConfiguration(ol);
> >>>> openLayers.exports("ol");
> >>>> mappedConfiguration
> >>>> .add("ol", openLayers);
> >>>> }
> >>>>
> >>>> What is the correct syntax to refer to inject this file as a resource?
> >>> The
> >>>> above class path syntax seems to be failing.
> >>>>
> >>>> Is there a pure Javascript way as well? Been trying to play with
> >>>> config/shim blocks but couldn't get it working.
> >>>>
> >>>> Any help would be appreciated.
> >>>>
> >>>> Best Regards,
> >>>> Sanket
> >>>
> >>>
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: RequireJS Shim and JavaScriptModuleConfiguration

Posted by Geoff Callender <ge...@gmail.com>.
Not a bug. 
If you put actual modules in resources/META-INF/modules/, then they work fine. 
Put non-modules in resources/META-INF/assets/ and make them available as modules as I showed below by contributing to ModuleManager.

On 18 Jun 2014, at 5:27 pm, Sanket Sharma <sa...@gmail.com> wrote:

> Okay, it works if I place my javascript under /META-INF/assets/js
> 
> Bug? Or does everything have to be under assets? It doesn't seem to pick up
> resources under META-INF/modules.
> 
> 
> On Wed, Jun 18, 2014 at 9:11 AM, Sanket Sharma <sa...@gmail.com>
> wrote:
> 
>> 
>> Nope. Doesn't work. I have my javascript files in the project under
>> resources resources/META-INF/modules/ol/ol.js
>> 
>> Does it map the META-INF/modules to a virtual resource? In your code I'm
>> as suing there is a folder under META-INF called assets/js?
>> 
>> If I use @Path("/META-INF/modules/ol/ol.js") corresponding to my folder
>> structure it fails with the error below:
>> Unable to locate asset 'classpath:modules.gz/modules/ol/ol.js' (the file
>> does not exist).
>> 
>> In the deployed file, it seems all javascript files are gzipped under
>> context-root/modules.gz And thats where its loading all the javascript from.
>> 
>> 
>> 
>> 
>> 
>> 
>> On Wed, Jun 18, 2014 at 3:41 AM, Geoff Callender <
>> geoff.callender.jumpstart@gmail.com> wrote:
>> 
>>> Here's one that worked, producing a module called jquery-ui:
>>> 
>>>    public static void
>>> contributeModuleManager(MappedConfiguration<String, Object> configuration,
>>>            @Path("/META-INF/assets/js/jquery-ui-1.9.1.js") Resource
>>> jqueryUi) {
>>>        configuration.add("jquery-ui", new
>>> JavaScriptModuleConfiguration(jqueryUi));
>>>    }
>>> 
>>> HTH,
>>> 
>>> Geoff
>>> 
>>> On 18 Jun 2014, at 10:25 am, Sanket Sharma <sa...@gmail.com>
>>> wrote:
>>> 
>>>> Hi,
>>>> 
>>>> How do I convert a non AMD javascript module to work with require.js?
>>>> 
>>>> I did some investigate and it seems like shimming is the way to go.
>>>> I would like to take a javascript file ol.js and shim to to export 'ol'.
>>>> The file is located under modules and is packaged in META-INF/modules
>>>> directory in the standard tapestry way.
>>>> 
>>>> Reading source code and documentation seems to suggest it can be done in
>>>> the following way:
>>>> 
>>>> @Contribute(ModuleManager.class)
>>>> public static void setupOpenLayersConfiguration(
>>>> MappedConfiguration<String, Object> mappedConfiguration,
>>>> @Inject @Path("classpath:META-INF/modules/ol/ol.js") Resource ol) {
>>>> JavaScriptModuleConfiguration openLayers = new
>>>> JavaScriptModuleConfiguration(ol);
>>>> openLayers.exports("ol");
>>>> mappedConfiguration
>>>> .add("ol", openLayers);
>>>> }
>>>> 
>>>> What is the correct syntax to refer to inject this file as a resource?
>>> The
>>>> above class path syntax seems to be failing.
>>>> 
>>>> Is there a pure Javascript way as well? Been trying to play with
>>>> config/shim blocks but couldn't get it working.
>>>> 
>>>> Any help would be appreciated.
>>>> 
>>>> Best Regards,
>>>> Sanket
>>> 
>>> 
>> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: RequireJS Shim and JavaScriptModuleConfiguration

Posted by Sanket Sharma <sa...@gmail.com>.
Okay, it works if I place my javascript under /META-INF/assets/js

Bug? Or does everything have to be under assets? It doesn't seem to pick up
resources under META-INF/modules.


On Wed, Jun 18, 2014 at 9:11 AM, Sanket Sharma <sa...@gmail.com>
wrote:

>
> Nope. Doesn't work. I have my javascript files in the project under
> resources resources/META-INF/modules/ol/ol.js
>
> Does it map the META-INF/modules to a virtual resource? In your code I'm
> as suing there is a folder under META-INF called assets/js?
>
> If I use @Path("/META-INF/modules/ol/ol.js") corresponding to my folder
> structure it fails with the error below:
> Unable to locate asset 'classpath:modules.gz/modules/ol/ol.js' (the file
> does not exist).
>
> In the deployed file, it seems all javascript files are gzipped under
> context-root/modules.gz And thats where its loading all the javascript from.
>
>
>
>
>
>
> On Wed, Jun 18, 2014 at 3:41 AM, Geoff Callender <
> geoff.callender.jumpstart@gmail.com> wrote:
>
>> Here's one that worked, producing a module called jquery-ui:
>>
>>     public static void
>> contributeModuleManager(MappedConfiguration<String, Object> configuration,
>>             @Path("/META-INF/assets/js/jquery-ui-1.9.1.js") Resource
>> jqueryUi) {
>>         configuration.add("jquery-ui", new
>> JavaScriptModuleConfiguration(jqueryUi));
>>     }
>>
>> HTH,
>>
>> Geoff
>>
>> On 18 Jun 2014, at 10:25 am, Sanket Sharma <sa...@gmail.com>
>> wrote:
>>
>> > Hi,
>> >
>> > How do I convert a non AMD javascript module to work with require.js?
>> >
>> > I did some investigate and it seems like shimming is the way to go.
>> > I would like to take a javascript file ol.js and shim to to export 'ol'.
>> > The file is located under modules and is packaged in META-INF/modules
>> > directory in the standard tapestry way.
>> >
>> > Reading source code and documentation seems to suggest it can be done in
>> > the following way:
>> >
>> > @Contribute(ModuleManager.class)
>> > public static void setupOpenLayersConfiguration(
>> > MappedConfiguration<String, Object> mappedConfiguration,
>> > @Inject @Path("classpath:META-INF/modules/ol/ol.js") Resource ol) {
>> > JavaScriptModuleConfiguration openLayers = new
>> > JavaScriptModuleConfiguration(ol);
>> > openLayers.exports("ol");
>> > mappedConfiguration
>> > .add("ol", openLayers);
>> > }
>> >
>> > What is the correct syntax to refer to inject this file as a resource?
>> The
>> > above class path syntax seems to be failing.
>> >
>> > Is there a pure Javascript way as well? Been trying to play with
>> > config/shim blocks but couldn't get it working.
>> >
>> > Any help would be appreciated.
>> >
>> > Best Regards,
>> > Sanket
>>
>>
>

Re: RequireJS Shim and JavaScriptModuleConfiguration

Posted by Geoff Callender <ge...@gmail.com>.
ol.js is not a module, it's an asset. That's why you're shimming it. So instead of putting it in resources/META-INF/modules/, try putting it in resources/META-INF/assets/js/.

On 18 Jun 2014, at 5:11 pm, Sanket Sharma <sa...@gmail.com> wrote:

> Nope. Doesn't work. I have my javascript files in the project under
> resources resources/META-INF/modules/ol/ol.js
> 
> Does it map the META-INF/modules to a virtual resource? In your code I'm as
> suing there is a folder under META-INF called assets/js?
> 
> If I use @Path("/META-INF/modules/ol/ol.js") corresponding to my folder
> structure it fails with the error below:
> Unable to locate asset 'classpath:modules.gz/modules/ol/ol.js' (the file
> does not exist).
> 
> In the deployed file, it seems all javascript files are gzipped under
> context-root/modules.gz And thats where its loading all the javascript from.
> 
> 
> 
> 
> 
> 
> On Wed, Jun 18, 2014 at 3:41 AM, Geoff Callender <
> geoff.callender.jumpstart@gmail.com> wrote:
> 
>> Here's one that worked, producing a module called jquery-ui:
>> 
>>    public static void contributeModuleManager(MappedConfiguration<String,
>> Object> configuration,
>>            @Path("/META-INF/assets/js/jquery-ui-1.9.1.js") Resource
>> jqueryUi) {
>>        configuration.add("jquery-ui", new
>> JavaScriptModuleConfiguration(jqueryUi));
>>    }
>> 
>> HTH,
>> 
>> Geoff
>> 
>> On 18 Jun 2014, at 10:25 am, Sanket Sharma <sa...@gmail.com> wrote:
>> 
>>> Hi,
>>> 
>>> How do I convert a non AMD javascript module to work with require.js?
>>> 
>>> I did some investigate and it seems like shimming is the way to go.
>>> I would like to take a javascript file ol.js and shim to to export 'ol'.
>>> The file is located under modules and is packaged in META-INF/modules
>>> directory in the standard tapestry way.
>>> 
>>> Reading source code and documentation seems to suggest it can be done in
>>> the following way:
>>> 
>>> @Contribute(ModuleManager.class)
>>> public static void setupOpenLayersConfiguration(
>>> MappedConfiguration<String, Object> mappedConfiguration,
>>> @Inject @Path("classpath:META-INF/modules/ol/ol.js") Resource ol) {
>>> JavaScriptModuleConfiguration openLayers = new
>>> JavaScriptModuleConfiguration(ol);
>>> openLayers.exports("ol");
>>> mappedConfiguration
>>> .add("ol", openLayers);
>>> }
>>> 
>>> What is the correct syntax to refer to inject this file as a resource?
>> The
>>> above class path syntax seems to be failing.
>>> 
>>> Is there a pure Javascript way as well? Been trying to play with
>>> config/shim blocks but couldn't get it working.
>>> 
>>> Any help would be appreciated.
>>> 
>>> Best Regards,
>>> Sanket
>> 
>> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: RequireJS Shim and JavaScriptModuleConfiguration

Posted by Sanket Sharma <sa...@gmail.com>.
Nope. Doesn't work. I have my javascript files in the project under
resources resources/META-INF/modules/ol/ol.js

Does it map the META-INF/modules to a virtual resource? In your code I'm as
suing there is a folder under META-INF called assets/js?

If I use @Path("/META-INF/modules/ol/ol.js") corresponding to my folder
structure it fails with the error below:
Unable to locate asset 'classpath:modules.gz/modules/ol/ol.js' (the file
does not exist).

In the deployed file, it seems all javascript files are gzipped under
context-root/modules.gz And thats where its loading all the javascript from.






On Wed, Jun 18, 2014 at 3:41 AM, Geoff Callender <
geoff.callender.jumpstart@gmail.com> wrote:

> Here's one that worked, producing a module called jquery-ui:
>
>     public static void contributeModuleManager(MappedConfiguration<String,
> Object> configuration,
>             @Path("/META-INF/assets/js/jquery-ui-1.9.1.js") Resource
> jqueryUi) {
>         configuration.add("jquery-ui", new
> JavaScriptModuleConfiguration(jqueryUi));
>     }
>
> HTH,
>
> Geoff
>
> On 18 Jun 2014, at 10:25 am, Sanket Sharma <sa...@gmail.com> wrote:
>
> > Hi,
> >
> > How do I convert a non AMD javascript module to work with require.js?
> >
> > I did some investigate and it seems like shimming is the way to go.
> > I would like to take a javascript file ol.js and shim to to export 'ol'.
> > The file is located under modules and is packaged in META-INF/modules
> > directory in the standard tapestry way.
> >
> > Reading source code and documentation seems to suggest it can be done in
> > the following way:
> >
> > @Contribute(ModuleManager.class)
> > public static void setupOpenLayersConfiguration(
> > MappedConfiguration<String, Object> mappedConfiguration,
> > @Inject @Path("classpath:META-INF/modules/ol/ol.js") Resource ol) {
> > JavaScriptModuleConfiguration openLayers = new
> > JavaScriptModuleConfiguration(ol);
> > openLayers.exports("ol");
> > mappedConfiguration
> > .add("ol", openLayers);
> > }
> >
> > What is the correct syntax to refer to inject this file as a resource?
> The
> > above class path syntax seems to be failing.
> >
> > Is there a pure Javascript way as well? Been trying to play with
> > config/shim blocks but couldn't get it working.
> >
> > Any help would be appreciated.
> >
> > Best Regards,
> > Sanket
>
>

Re: RequireJS Shim and JavaScriptModuleConfiguration

Posted by Geoff Callender <ge...@gmail.com>.
Here's one that worked, producing a module called jquery-ui:

    public static void contributeModuleManager(MappedConfiguration<String, Object> configuration,
            @Path("/META-INF/assets/js/jquery-ui-1.9.1.js") Resource jqueryUi) {
        configuration.add("jquery-ui", new JavaScriptModuleConfiguration(jqueryUi));
    }

HTH,

Geoff

On 18 Jun 2014, at 10:25 am, Sanket Sharma <sa...@gmail.com> wrote:

> Hi,
> 
> How do I convert a non AMD javascript module to work with require.js?
> 
> I did some investigate and it seems like shimming is the way to go.
> I would like to take a javascript file ol.js and shim to to export 'ol'.
> The file is located under modules and is packaged in META-INF/modules
> directory in the standard tapestry way.
> 
> Reading source code and documentation seems to suggest it can be done in
> the following way:
> 
> @Contribute(ModuleManager.class)
> public static void setupOpenLayersConfiguration(
> MappedConfiguration<String, Object> mappedConfiguration,
> @Inject @Path("classpath:META-INF/modules/ol/ol.js") Resource ol) {
> JavaScriptModuleConfiguration openLayers = new
> JavaScriptModuleConfiguration(ol);
> openLayers.exports("ol");
> mappedConfiguration
> .add("ol", openLayers);
> }
> 
> What is the correct syntax to refer to inject this file as a resource? The
> above class path syntax seems to be failing.
> 
> Is there a pure Javascript way as well? Been trying to play with
> config/shim blocks but couldn't get it working.
> 
> Any help would be appreciated.
> 
> Best Regards,
> Sanket