Last active
March 1, 2018 17:44
-
-
Save kumatch/7857227 to your computer and use it in GitHub Desktop.
A browserify simple example.
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
var format = require('util').format; | |
module.exports = function (v) { | |
if (typeof v === "string") { | |
return format('%s OK.', v); | |
} else if (typeof v === "number") { | |
return v * 10; | |
} else { | |
return v; | |
} | |
}; |
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
var async = require('async'); | |
var baz = require('./bar/baz'); | |
exports.run = function (values, callback) { | |
async.map(values, function (v, next) { | |
next(null, baz(v)); | |
}, callback); | |
}; |
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(grunt) { | |
var pkg = grunt.file.readJSON('package.json'); | |
grunt.initConfig({ | |
browserify: { | |
dist: { | |
src: 'main.js', | |
dest: 'build.js' | |
} | |
} | |
}); | |
Object.keys(pkg.devDependencies).forEach(function (devDependency) { | |
if (devDependency.match(/^grunt\-/)) { | |
grunt.loadNpmTasks(devDependency); | |
} | |
}); | |
grunt.registerTask('default', [ 'browserify' ]); | |
}; |
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
<html> | |
<head> | |
</head> | |
<body> | |
<div id="content"></div> | |
<script src="build.js"></script> | |
</body> | |
</html> |
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
var foo = require('./lib/foo.js'); | |
var content = document.getElementById('content'); | |
foo.run([ 3, 10, "foo", "bar", 42 ], function (err, results) { | |
if (err) throw err; | |
results.forEach(function (r) { | |
content.innerHTML += ' ' + r; | |
}); | |
}); |
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
{ | |
"private": true, | |
"dependencies": { | |
"async": "0.2.9" | |
}, | |
"devDependencies": { | |
"grunt": "~0.4", | |
"grunt-browserify": "*" | |
}, | |
"optionalDependencies": {}, | |
"engines": { | |
"node": ">= 0.8.0" | |
} | |
} |
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
@ / | |
├─ Gruntfile.js | |
├─ package.json | |
├─ index.html | |
├─ main.js | |
└┬ lib/ | |
├─ foo.js | |
└┬ bar/ | |
└─ baz.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment