0

We are planning on versioning our key resources at build time by appending a version to the filename (e.g. main-v1_1.js)

We are learning how to use require.js to manage our resource loading. I would like to be able to specify a postfix in the require.js configuration that will be appended to the resources being loaded.

var version = "1_1";  //inserted at build time
requirejs.config(
   {
      postfix: "_" + version  //is there something like this?
   }
);
require([main]...); //would load main_1_1.js

Suggestions? Thoughts? Better ways to handle this situation?

Thank you.

4

2 に答える 2

0

これはマップ構成オプションに適しているように思えます。

requirejs.config({
    map: {
        'some/newmodule': {
            'foo': 'foo1.2'
        },
        'some/oldmodule': {
            'foo': 'foo1.0'
        }
    }
});

「some/newmodule」が実行require('foo')すると foo1.2.js ファイルが取得され、「some/oldmodule」が実行require('foo')されると foo1.0.js ファイルが取得されます。この機能は、define() を呼び出して匿名モジュールとして登録する実際の AMD モジュールであるスクリプトに対してのみ適切に機能します。

于 2012-11-22T09:00:38.877 に答える