Skip to content
This repository

almond integration #3

Closed
jzaefferer opened this Issue May 21, 2012 · 8 comments

2 participants

Jörn Zaefferer Sebastian Golasch
Jörn Zaefferer

This is more of a support request then a bug report. I've got pretty far along, though can't get the almond integration working.

My config looks like this:

requirejs: {
    almond: true,
    replaceRequireScript: [{
        files: ['index.html'],
        module: '/js/main-built'
    }],
    baseUrl: "js",
    paths: {
        'hbs': 'libs/hbs',
        'Handlebars': 'libs/Handlebars',
        'Backbone': 'libs/backbone',
        'underscore': 'libs/underscore',
        'bootstrap': 'libs/bootstrap',
        'json2': 'libs/json2',
        'Rickshaw': 'libs/rickshaw',
        'validate': 'libs/jquery.validate'
    },
    hbs: {
        templateExtension : 'hbs',
        stylesDir : '/static/css/',
        disableI18n: true
    },
    modules: [{name: 'main'}],
    out: "js/main-built.js"
}

There are multiple issues:

  • replaceRequireScript with almond:true has no effect, even though it would still be useful in this setup
  • the module property of items in the replaceRequireScript array is ignored, though I'd like that to be used for the src-attribute in tasks/require.js:146
  • Once the above works, I end up with a main-built.js. When loading that, I get a script error about window.require being undefined. My main.js calls require. If I change that to use define, I don't get an error, but nothing is executed.

So close...

Sebastian Golasch
Owner

Mhh,

could you try to replace the "module" property in the "replaceRequireScript" property with the name of the main module?!

Yours:

    replaceRequireScript: [{
        files: ['index.html'],
        module: '/js/main-built'
    }]

How i think that it should look like:

    replaceRequireScript: [{
        files: ['index.html'],
        module: 'main'
    }]

Please tell me if that helped.
Else i will look deeper into that issue ;)

Regards.

Jörn Zaefferer

That doesn't help. Currently that property is ignored, only the files property is used.

Sebastian Golasch
Owner

Ahh, got it.
Lets see if i can fix this within the next hour ;)
Hold on...

Sebastian Golasch asciidisco closed this in 52096b0 May 21, 2012
Sebastian Golasch asciidisco reopened this May 21, 2012
Sebastian Golasch
Owner

You are now able to add a 'modulePath' configuration setting to your replaceRequireScript config.
I´ve also added this to the README, that´s something you have to do, when specifying the 'out' property.

Hopefully that helps:

    replaceRequireScript: [{
        files: ['index.html'],
        module: 'main',
        modulePath: '/js/main-built'
    }]

I don´t know if we get rid off all your issues, but this might be a step towards.
I tested it roughly with a configuration similar to yours.

Jörn Zaefferer

That fixes the almond aspect, but I still have the other problem mentioned above:

  • Once the above works, I end up with a main-built.js. When loading that, I get a script error about window.require being undefined. My main.js calls require. If I change that to use define, I don't get an error, but nothing is executed.

Actually require exists, but isn't a function. No idea yet why that isn't working.

Sebastian Golasch
Owner

Just a guess,
have you tried to wrap your generated file like shown here:

https://github.com/jrburke/almond#usage

Jörn Zaefferer

That works! Dunno why, but that's okay. Maybe add wrap:true to the example in the readme?

Sebastian Golasch
Owner

Yeah, snd. time a hear from someone using the plugin successfully :D

I don´t know why, in my configuration, if i add wrap=true, i get some weird errors.
Maybe it´s about the layout of my main.js module file...

Nevertheless,
i added some info to the readme about the wrap issue,
closing this one here.

Sebastian Golasch asciidisco closed this May 21, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.