Last active
August 29, 2015 13:58
-
-
Save jfsiii/9982955 to your computer and use it in GitHub Desktop.
Trying to do common + page pattern. How do I build this with the API? https://github.com/substack/node-browserify#methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var browserify = require('browserify'); | |
var bowerResolve = require('bower-resolve'); | |
// shared / common | |
bowerResolve.init(function(){ | |
var bCfg = { | |
basedir: '/path/to/repo', | |
noParse: [bowerResolve('jquery')] | |
}; | |
var writestream = require('fs').createWriteStream('./src/main/resources/static/js/common.js'); | |
browserify(bCfg) | |
.require(bowerResolve('jquery'), { expose: 'jquery' }) | |
.require(bowerResolve('flight', {expose: 'flight'})) | |
.add('./src/main/js/common.js') | |
.transform('deamdify') | |
.transform('debowerify') | |
.bundle() | |
.pipe(writestream); | |
// about (logged-out) | |
var writestream = require('fs').createWriteStream('./src/main/resources/static/js/about.js'); | |
browserify(bCfg) | |
.external('jquery') | |
.external('flight') | |
.add('./src/main/js/page/about.js') | |
.bundle() | |
.pipe(writestream); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## This works as expected | |
## Make the common bundle | |
$(npm bin)/browserify \ | |
-t debowerify \ | |
-t deamdify \ | |
-r ./src/main/js/common.js \ | |
> src/main/resources/static/js/common.js | |
## Make the page bundle | |
$(npm bin)/browserify \ | |
-t deamdify \ | |
-t debowerify \ | |
-x ./lib/bower_components/jquery/jquery.js \ | |
-x ./lib/bower_components/flight/lib/index.js \ | |
./src/main/js/page/about.js \ | |
> ./src/main/resources/static/js/about.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vendor modules | |
// located in lib/bower_components | |
require('es5-shim/es5-shim'); | |
require('es5-shim/es5-sham'); | |
require('jquery'); | |
require('flight'); | |
require('bootstrap'); | |
// our modules | |
require('./ui/analytics'); | |
require('./ui/analytics_listener').attachTo(document.body); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="common.js"></script> | |
<script src="page.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (nodeOrSelector) { | |
// use "jquery" supplied by "common" | |
var $ = require("jquery"); | |
// do page stuff with jquery or other modules from "common" | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment