Frage

I'm using RequireJS for my javascript project, and r.js to build one single javascript file for production. This single file (main.js) is then uploaded to a CDN. This all works very fine, but now I'm trying to add i18n support.

The problem is that the location of the i18n file is relative to the main javascript file. So within a module, I would have:

define(['i18n!nls/text'], function(Translation) { });

This all works very fine when I'm developing, but for production the problem is that the translation file is not relative to the main.js file as this is placed in a CDN. I don't want to store the translation file in the CDN, so how do I change the reference to that file in the build process?

War es hilfreich?

Lösung

I found a solution to my problem. In the RequireJS config I've added:

requirejs.config({
    paths: {
        nls: "/js/nls"
    }
});

Because the path starts with a slash, RequireJS knows it's not relative. Now the problem I got was that the build would fail, as RequireJS would be looking for default language files in /js/nls. Therefore, I added a symlink from the root of my webserver to the nls directory on the machine.

Andere Tipps

Had the same issue.

Use baseUrl config

require.config({
    baseUrl: '/path_for_not_included_modules/'
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top