2

1 つではなく 2 つのバンドルにバンドルしたい大規模なクライアント側プロジェクトがあります。

これは私の依存関係ツリーです:

モジュールの依存関係ツリー

望ましい出力は、これらのバンドルを持つことです。

  1. main含むb
  2. xこれにはab最初のバンドルにすでに含まれており、ユーザーがコードを複数回ダウンロードすることは望ましくありません)。

これが私のオプティマイザ構成です。

({
  appDir: 'www',
  baseUrl: 'js/',
  mainConfigFile: 'www/js/require.config.js',
  dir: 'www-release',
  modules: [
    {
      name: 'main',
      exclude: ['x']
    },
    {
      name: 'x',
      exclude: ['main']
    }
  ],
  optimize: 'none',
  removeCombined: true
})

mainの依存関係ツリー全体から除外したいのですxが、明示的に必要なモジュール ( a.

そんなこと知ってる:

  1. include— 直接必要のないモジュールとその依存関係ツリー全体を明示的に含めます。
  2. exclude— モジュールを除外すると、実際にはその依存関係ツリー全体が除外されinclude、競合が発生した場合にオーバーライドされます。
  3. excludeShallow—モジュール自体を含ま、モジュールの依存関係ツリーを含みます。

それを持っていると、私が望むものを達成するための明確な方法がわかりません。助けてもらえますか?

4

1 に答える 1

1

このような requier.js バンドル機能を使用する必要があります。

require.config.js ファイルで

バンドル設定の書き込みが必要

bundles: {
    x: ['files for x bundle'],
    b: ['files for b bundle']
}

この後、ビルドファイルを変更する必要があります。

オプティマイザ構成ファイル

({
     appDir: 'www',
     baseUrl: 'js/',
    // mainConfigFile: 'www/js/require.config.js',// not need here
     dir: 'www-release',
     modules: [
        {
            name: 'main',
            create: true, // this will create www-release/main.js file(main bundle)
            include: ['main'],
            exclude: ['x']
        },
        {
            name: 'b',
            create: true,
            include: ['files for b bundle'],
            exclude: ['main']
        },
        {
            name: 'x',
            create: true,
            include: ['files for x bundle']
            exclude: ['main']
        }
   ],
   optimize: 'none',
   removeCombined: true
   paths: {
       //put paths object from requierjs.confige file 
   }
});
于 2016-10-31T09:00:24.177 に答える