browserify / browserify/factor-bundle

Factor-bundle and browserify-shim don't play well together

オープン
#59 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
JavaScript
スター
397
フォーク
24
PR マージ指標
30日以内にマージされた PR はありません

説明

We were using browserify with browserify-shim to be able to use jQuery with a few plugins. So far so good. At this time we were creating another bundle for dependencies common across all pages, manually specifying them.

We then discovered and decided to use factor-bundle to factor common dependencies in a better way. The result was very good in terms of file size, but shims provided by browserify-shim disappeared. Since jQuery and its plugins are used in several pages, they're successfully factored out with factor-bundle, but they're produced without the shims. The problem is that jQuery plugins rely in window.jQuery that's no more available since there's no more shim.

We ended up requireing jQuery manually in the HTML and expose it, with <script>var jQuery = require("jquery")</script>. We would love factor-bundle to work with browserify-shim (or the opposite, whatever).

My understanding is that since factor-bundle is a plugin that act at the bundle level, it may not call it properly. But in our setup, it successfully apply the reactify transform (we use React.js with JSX syntax). So I suppose it's not a problem of factor-bundle not using transforms at all, but a specific incompatibility between factor-bundle and browserify-shim. However I couln't determine the problem precisely since I'm not familiar at all with the internals of those modules.

For reference in case it helps, here are relevant parts of our package.json and gulpfile (some parts are skipped to focus, it may look inconsistent/weird) :

package.json

  "browserify": {
    "transform": [
      "reactify",
      "browserify-shim"
    ]
  },
  "browser": {
    "jquery": "./node_modules/jquery/dist/jquery.js",
    "twitter-typeahead": "./node_modules/typeahead.js/dist/typeahead.bundle.js",
    "magnific-popup": "./node_modules/magnific-popup/dist/jquery.magnific-popup.js"
  },
  "browserify-shim": {
    "jquery": "$",
    "slick-carousel": {
      "depends": [
        "jquery"
      ]
    },
    "twitter-typeahead": {
      "depends": [
        "jquery"
      ]
    },
    "magnific-popup": {
      "depends": [
        "jquery"
      ]
    }
  }

gulpfile.js

function browserifyPages() {
    var pages = fs.readdirSync("./pages");

    var b = browserify(pages.map(function (p) {
        return "./pages/" + p;
    }), BROWSERIFY_ARGS);
    b.require("jquery");

    b = minifyBundle(b); // using minifyify
    return b.plugin("factor-bundle", {outputs: pages.map(function (p) {
            return JS_DST_DIR + "/" + p;
        })});
}

function browserifyCommonJs() {
    var b = browserify("./common/header.js", BROWSERIFY_ARGS);
    b.external("jquery");
    return minifyBundle(b);
}

Hope this helps identify the problem. Thanks in advance.

(Let me ping browserify-shim people : @thlorenz and @bendrucker. In case I shouldn't, sorry guys !)

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

package.json と gulpfile.js から始め、factor-bundle のプラグインエントリポイントと browserify-shim による jquery 依存関係の処理を追跡します。示されている pages/common セットアップから factor-bundle の出力を再現し、jquery プラグインが手動の HTML require なしで window.jQuery を保持することを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, jquery, react
領域
build-system, tooling
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。