Inline global ressource and webpack build for production

Dear all,

I need a Base64 value converter, since it is a cross-cutting concern and given how short is the toView implementation I declare it as a inline global resource:

        .globalResources(class Base64ValueConverter {
            toView(value: string) {
                return window.btoa(value);

But the production build does not work: Cannot determine default view strategy for object.
class{toView(e){return window.btoa(e)}}

I know that I can declare the value converter in a specific file and reference it with Plaform.moduleName but I’d rather not have a specific file for this one line converter. Is there any other way ?


I think that you might need to use the @valueConverter decorator. If you are keen on using the inline construct, then you might need to use the decorator like a function: valueConverter(class ... { /*..*/ }).

Thanks, but valueConverter(class ... { /*..*/ }) does not compile because valueConverter function expect a string.

the following code

.globalResources(valueConverter('base64')( class Base64ValueConverter {
            toView(value: string) {
                return window.btoa(value);

compiles but fails at runtime:

Invalid resource [undefined], resource must be specified as functions or relative module IDs.

Did I miss something ? I would be happy to give a function…

I think the aurelia1 loaders are interfering with this. Not sure if such inlined registrations are supported in aurelia1.

Indeed, this code works with aurelia v2:

    .register(valueConverter(class Base64ValueConverter {
        toView(s: string) {
            return window.btoa(s);