browserify-common-prelude

0.5.4 • Public • Published

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>

Readme

Keywords

Package Sidebar

Install

npm i browserify-common-prelude

Weekly Downloads

1

Version

0.5.4

License

MIT

Last publish

Collaborators

  • undozen