Custom module loaders and script tags

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Custom module loaders and script tags

Guy Bedford
I'm trying to work out how custom module loaders can be used with standard script tags.

For example, say I create a RequireJS-style loader (with an identical configuration API including map config etc), and want to use this within a script file loaded via a script tag:

<script>
  var RequireJSStyleLoader = new Loader({
    // ... etc ...
  });
</script>
<script src="some/module/file.js"></script>

How do I configure the loader to know that "some/module/file.js" should have its imports and module declarations applied with my custom loader (RequireJSStyleLoader) and not the system loader?

Or is it only possible to set a custom loader for imports executed with RequireJSStyleLoader.load(...)?

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Custom module loaders and script tags

Sam Tobin-Hochstadt
On Fri, Jun 7, 2013 at 11:29 PM, Guy Bedford <[hidden email]> wrote:

> I'm trying to work out how custom module loaders can be used with standard
> script tags.
>
> For example, say I create a RequireJS-style loader (with an identical
> configuration API including map config etc), and want to use this within a
> script file loaded via a script tag:
>
> <script>
>   var RequireJSStyleLoader = new Loader({
>     // ... etc ...
>   });
> </script>
> <script src="some/module/file.js"></script>
>
> How do I configure the loader to know that "some/module/file.js" should have
> its imports and module declarations applied with my custom loader
> (RequireJSStyleLoader) and not the system loader?
>
> Or is it only possible to set a custom loader for imports executed with
> RequireJSStyleLoader.load(...)?

Currently, that's all that's possible. Dave and I plan to talk to
people on the HTML side to enable this as well, but that has not yet
begun.

Sam
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Custom module loaders and script tags

Guy Bedford
Would it be better simply to override the default system loader, or would this be discouraged?

I notice Yehuda's examples are based on overloading of the System loader, so perhaps this will be the standard method.

On 8 June 2013 06:47, Sam Tobin-Hochstadt <[hidden email]> wrote:
On Fri, Jun 7, 2013 at 11:29 PM, Guy Bedford <[hidden email]> wrote:
> I'm trying to work out how custom module loaders can be used with standard
> script tags.
>
> For example, say I create a RequireJS-style loader (with an identical
> configuration API including map config etc), and want to use this within a
> script file loaded via a script tag:
>
> <script>
>   var RequireJSStyleLoader = new Loader({
>     // ... etc ...
>   });
> </script>
> <script src="some/module/file.js"></script>
>
> How do I configure the loader to know that "some/module/file.js" should have
> its imports and module declarations applied with my custom loader
> (RequireJSStyleLoader) and not the system loader?
>
> Or is it only possible to set a custom loader for imports executed with
> RequireJSStyleLoader.load(...)?

Currently, that's all that's possible. Dave and I plan to talk to
people on the HTML side to enable this as well, but that has not yet
begun.

Sam


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Custom module loaders and script tags

Sam Tobin-Hochstadt
On Sat, Jun 8, 2013 at 3:56 PM, Guy Bedford <[hidden email]> wrote:
> Would it be better simply to override the default system loader, or would
> this be discouraged?
>
> I notice Yehuda's examples are based on overloading of the System loader, so
> perhaps this will be the standard method.

We expect that modifying the System loader will be common, and
creating new Loaders will be reserved for when new isolated context
are required.

Sam

>
>
> On 8 June 2013 06:47, Sam Tobin-Hochstadt <[hidden email]> wrote:
>>
>> On Fri, Jun 7, 2013 at 11:29 PM, Guy Bedford <[hidden email]>
>> wrote:
>> > I'm trying to work out how custom module loaders can be used with
>> > standard
>> > script tags.
>> >
>> > For example, say I create a RequireJS-style loader (with an identical
>> > configuration API including map config etc), and want to use this within
>> > a
>> > script file loaded via a script tag:
>> >
>> > <script>
>> >   var RequireJSStyleLoader = new Loader({
>> >     // ... etc ...
>> >   });
>> > </script>
>> > <script src="some/module/file.js"></script>
>> >
>> > How do I configure the loader to know that "some/module/file.js" should
>> > have
>> > its imports and module declarations applied with my custom loader
>> > (RequireJSStyleLoader) and not the system loader?
>> >
>> > Or is it only possible to set a custom loader for imports executed with
>> > RequireJSStyleLoader.load(...)?
>>
>> Currently, that's all that's possible. Dave and I plan to talk to
>> people on the HTML side to enable this as well, but that has not yet
>> begun.
>>
>> Sam
>
>
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Custom module loaders and script tags

Guy Bedford
Ok sure, good to know, that makes a lot more sense. That covers my other post as well then. Reading the specs, it seemed like "new Loader" was the common form, and the idea of modifying a system global sounds like something generally to avoid, but here it does seem like it will be the better option in many cases.

On 8 June 2013 12:58, Sam Tobin-Hochstadt <[hidden email]> wrote:
On Sat, Jun 8, 2013 at 3:56 PM, Guy Bedford <[hidden email]> wrote:
> Would it be better simply to override the default system loader, or would
> this be discouraged?
>
> I notice Yehuda's examples are based on overloading of the System loader, so
> perhaps this will be the standard method.

We expect that modifying the System loader will be common, and
creating new Loaders will be reserved for when new isolated context
are required.

Sam

>
>
> On 8 June 2013 06:47, Sam Tobin-Hochstadt <[hidden email]> wrote:
>>
>> On Fri, Jun 7, 2013 at 11:29 PM, Guy Bedford <[hidden email]>
>> wrote:
>> > I'm trying to work out how custom module loaders can be used with
>> > standard
>> > script tags.
>> >
>> > For example, say I create a RequireJS-style loader (with an identical
>> > configuration API including map config etc), and want to use this within
>> > a
>> > script file loaded via a script tag:
>> >
>> > <script>
>> >   var RequireJSStyleLoader = new Loader({
>> >     // ... etc ...
>> >   });
>> > </script>
>> > <script src="some/module/file.js"></script>
>> >
>> > How do I configure the loader to know that "some/module/file.js" should
>> > have
>> > its imports and module declarations applied with my custom loader
>> > (RequireJSStyleLoader) and not the system loader?
>> >
>> > Or is it only possible to set a custom loader for imports executed with
>> > RequireJSStyleLoader.load(...)?
>>
>> Currently, that's all that's possible. Dave and I plan to talk to
>> people on the HTML side to enable this as well, but that has not yet
>> begun.
>>
>> Sam
>
>


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss