forked from joepie91/budo-express
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
934 B
JavaScript
35 lines
934 B
JavaScript
"use strict";
|
|
|
|
const Promise = require("bluebird");
|
|
const path = require("path");
|
|
const browserify = require("browserify");
|
|
const util = require("util");
|
|
const fs = require("fs");
|
|
const chalk = require("chalk");
|
|
|
|
let mkdirAsync = util.promisify(fs.mkdir);
|
|
|
|
module.exports = function bundle({ options, staticPath, entryPaths }) {
|
|
let targetBundlePath = staticPath(options.bundlePath);
|
|
let targetFolder = path.dirname(targetBundlePath);
|
|
|
|
let browserifyOptions = {
|
|
debug: options.sourceMaps,
|
|
... options.browserify
|
|
};
|
|
|
|
let browserifyInstance = browserify(browserifyOptions);
|
|
browserifyInstance.add(entryPaths);
|
|
|
|
return Promise.try(() => {
|
|
return mkdirAsync(targetFolder, { recursive: true });
|
|
}).then(() => {
|
|
return browserifyInstance
|
|
.bundle()
|
|
.pipe(fs.createWriteStream(targetBundlePath))
|
|
.on("finish", () => {
|
|
console.log(`${chalk.bold.green("Bundle generated:")} ${targetBundlePath}`);
|
|
});
|
|
});
|
|
};
|