Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including browserify-common-prelude with all npm packages installed. Try it out:

var browserifyCommonPrelude = require("browserify-common-prelude")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

browserify-common-prelude v0.5.4

browserify common prelude

browserify-common-prelude

installation

npm i --save browserify-common-prelude

usage

Better use with factor-bundle (gulp plugin). Best thing of it is that let you add async defer attributes to script tags and prevent block HTML downloading.

// build.js
// ...
var bcp = fs.readFileSync(require.resolve('browserify-common-prelude/dist/bcp.min.js'), 'utf-8');
browserify({
    prelude: bcp
})
.require('jquery')
.require('bluebird')
.bundle()
.pipe(fs.createWriteStream('./global.js'));

browserify({
    prelude: bcp
})
.require('chart.js')
.require('moment')
.bundle()
.pipe(fs.createWriteStream('./account.js'));

browserify({
    prelude: bcp
})
.add('./a.js')
.external(['jquery', 'bluebird'])
.bundle()
.pipe(fs.createWriteStream('./a.bundle.js'));

browserify({
    prelude: bcp
})
.add('./b.js')
.external(['jquery', 'bluebird', 'chart.js', 'moment'])
.bundle()
.pipe(fs.createWriteStream('./b.bundle.js'));
<!doctype html>
<!-- a.html - only one common lib, data-common attribute could be omitted -->
<script src="/global.js" async defer></script>
<script src="/a.bundle.js" async defer></script>
<!doctype html>
<!-- b.html - script tags with data-common attribute must be one after another, no other tags in between -->
<script src="/global.js" data-common async defer></script>
<script src="/account.js" data-common async defer></script>
<script src="/b.bundle.js" async defer></script>
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free