node.js - Browserifying react with addons to a standalone component, usable by plugins -
i experementing bit react , browserify , have these wishes:
- i want bundle code written me single file
- i want bundle 3rd party dependencies (react, react-router, lodash etc) separate files, 1 each lib, maximize caching possibilities
i have managed things described above ran specific situation:
in places of code want use react addons , such require this: var react = require('react/addons). don't in parts of code , not done in 3rd party dependencies such react-router. seems create conflict. either browserified bundle available through var react = require('react/addons) breaks 3rd party dependencies, or have bundle react both or without addons menas react bundled , downloaded twice.
i tried use aliasify , make react alias react/addons couldn't make work. should possible?
another acceptable solution bundle just addons in separate bundle , through make both react , react/addons available through calls require. of possible?
addition comment first comment brandontilley, not applicable react , addons. lodash comes number of different distributions , able choose version use in webapp in case well.
notice want achieve documented here: browserify partitionning
i'm packaging app in 2 parts: applibs.js , app.js. i've done caching choose put code not change in single bundle instead of splitting want, can use same trick.
here's code might interest you:
var libs = [ "react", "react/addons", // see why: https://github.com/substack/node-browserify/issues/1161 ... other libs ]; gulp.task('browserify-libs', function () { var b = browserify(...); libs.foreach(function(lib) { b.require(lib); }); return b.bundle()....... }); gulp.task('browserify',['browserify-libs'],function () { var b = browserify(...); libs.foreach(function(lib) { b.external(lib); }); return b.bundle()....... }); this way, react bundled once in applibs.js , can required inside app.js using both react , react/addons
if want bundle libs in separate files, bundle b.require("mylib"), in case sure check libraries not have direct dependencies. if lib bundle has dependency in react, means lib packaged in bundle, potentially leading multiple bundles having react inside them (and making weird failures @ runtime). library should rather use peerdependencies b.require not try package these dependencies
Comments
Post a Comment