browserify-adventure
Version:
learn browserify with this educational adventure
26 lines (18 loc) • 849 B
Plain Text
Here's the reference solution entry point (main.js):
var uniquely = require('./uniquely.js');
var result = uniquely(prompt());
console.log(result);
and this is the reference uniquely.js:
var uniq = require('uniq');
module.exports = function (str) {
return uniq(str.split(','));
};
As we've just seen, `module` is a special variable pre-defined in node and
browserify for each file. We used `module.exports` to export a single
function from `uniquely.js` that we used from our entry point, main.js.
browserify concatenated all the files together into a single file that
can be shipped to browsers, even though there are multiple files being
loaded.
We also saw the difference between loading local packages with a relative
path (`require('./uniquely.js'`) and loading packages that we installed
with npm (`require('uniq')`).