i'm encountering puzzling issue browserify, regarding jquery plugins. have multiple bundles separate sub-apps, have global libraries <script> tags in html prevent repetition.
i'm using gulp, browserify-shim , babelify create bundles.
within package.json:
"dependencies": { "jquery.cookie": "^1.4.1", ... }, "browserify-shim": { "jquery": "global:jquery", ... }, "browserify": { "transform": [ "browserify-shim" ] } within base.html: (in production these cdn links)
<!--[if lt ie 9]><script src="/bower_components/jquery-legacy/jquery.min.js"></script><![endif]--> <!--[if gte ie 9]><!--> <script src="/bower_components/jquery/dist/jquery.min.js"></script> <!--<![endif]--> in 1 of source files:
import $ 'jquery'; // works import 'jquery.cookie'; // crashes browserify error message:
error: cannot find module 'jquery' '/path/to/node_modules/jquery.cookie' jquery not installed npm not want rolled bundles.
i'm guessing issue here there call require('jquery') within jquery.cookie.js not being resolved.
how 'fake' existence of global jquery instance plugin browserify-shim?
nb: this solution not meet needs, jquery rolled many bundles.
solved. this solution seems work perfectly.
for reference, here (fixed) watchify call gulpfile:
var b = browserify({ entries: [app.input_dir + app.entry], debug: true, cache: {}, packagecache: {}, fullpaths: true }) .transform(babelify) .transform({ global: true }, 'browserify-shim') .plugin('minifyify', { map: app.output_dir + app.entry + '.map', output: app.output_dir + app.entry + '.map' }); var watcher = watchify(b);
Comments
Post a Comment