browserify / factor-bundle

factor browser-pack bundles into common shared bundles
Other
400 stars 27 forks source link

Fails if the output directory doesn't exist #49

Closed flipchart closed 9 years ago

flipchart commented 9 years ago

If you specify a directory in the output parameter which doesn't exist, then factor-bundle fails with the following message:

Error: ENOENT, open 'C:\path\to\output\x.js'
Process terminated with code 8.

Script being executed:

var browserify = require("browserify");
var fs = require("fs");

var files = ["./Scripts/test/x.js", "./Scripts/test/y.js"];
var b = browserify(files);
b
    .plugin("factor-bundle", {
        outputs: ["output/x.js", "output/y.js"], });
b
    .bundle()
    .pipe(fs.createWriteStream("wwwroot/common.js"));

Input scripts as per homepage example.

Environment: Windows 8.1 x64 Node.js v0.10.33 Browserify 8.0.2 factor-bundle 2.3.3

torgeir commented 9 years ago

I'm also seeing this one.

terinjokes commented 9 years ago

fs.createWriteStream from Node.js core doesn't create directories. Create the directory before running your script, or use fs.mkdir or the mkdirp module.

var browserify = require("browserify");
var path = require('path');
var fs = require("fs");

var files = ["./Scripts/test/x.js", "./Scripts/test/y.js"];
var outputDirectory = "./wwwroot";

fs.mkdir(outputDirectory, function (err) {
    if (err) {
        throw err;
    }

    var b = browserify(files);

    b.plugin("factor-bundle", {
        outputs: ["output/x.js", "output/y.js"],
    });

    b.bundle().pipe(fs.createWriteStream(path.join(outputdir, "./common.js")));
});