broccoli-webpack-cached
Advanced tools
Comparing version 0.1.3 to 0.1.4
63
index.js
@@ -12,3 +12,2 @@ 'use strict'; | ||
function WebpackFilter(inputNode, options) { | ||
@@ -36,2 +35,4 @@ if (!(this instanceof WebpackFilter)) return new WebpackFilter(inputNode, options); | ||
var resp, cwd; | ||
// Input tree path from broccoli | ||
@@ -55,2 +56,7 @@ this.options.context = this.inputPaths[0]; | ||
// Change our working directory so resolve.modulesDirectories searches the | ||
// latest broccoli piped version of our project rather than the original copies on disk. | ||
cwd = process.cwd(); | ||
process.chdir(this.inputPaths[0]); | ||
// Let webpack do all the caching (we will call webpack's compile method every | ||
@@ -61,3 +67,3 @@ // build and rely on it to only build what is necessary) | ||
// By default, log webpack's output to the console | ||
this.options.logStats = this.options.logStats || true; | ||
this.options.logStats = (this.options.logStats === undefined) ? true : this.options.logStats; | ||
@@ -74,3 +80,8 @@ // Prevent Webpack's ResultSymlinkPlugin from breaking relative paths in symlinked | ||
return webpack(this.options); | ||
// Run webpack | ||
resp = webpack(this.options); | ||
// Switch back to original working directory | ||
process.chdir(cwd); | ||
return resp; | ||
} | ||
@@ -87,35 +98,27 @@ | ||
that.compiler.run(function(err, stats) { | ||
var jsonStats = stats.toJson(); | ||
if (that.options.logStats) { | ||
var loggingOptions; | ||
// Allow options.logStats to be a string or object that is passed to | ||
// stats.toString(). More info in: | ||
// - http://webpack.github.io/docs/node.js-api.html#stats-tostring | ||
// - https://github.com/webpack/webpack/pull/1323 | ||
if (that.options.logStats === true) { | ||
loggingOptions = 'verbose'; | ||
} else { | ||
loggingOptions = that.options.logStats; | ||
} | ||
console.log("\n[webpack]", stats.toString(loggingOptions)); | ||
// If there is a Webpack error, show it and reject | ||
if(err){ | ||
console.error('Error in', err.module.rawRequest); | ||
console.log(err.message); | ||
console.log(err.details); | ||
reject(err); | ||
} | ||
// If we finished, show the logging we want to see | ||
var jsonStats = stats.toJson(); | ||
if (that.options.logStats) console.log("\n[webpack]", stats.toString(that.options.logStats)); | ||
if (jsonStats.errors.length > 0) jsonStats.errors.forEach(console.error); | ||
if (jsonStats.warnings.length > 0) jsonStats.warnings.forEach(console.warn); | ||
if (err || jsonStats.errors.length > 0) { | ||
reject(err); | ||
} else { | ||
// Get all of the assets from webpack, both emitted in this current compile | ||
// pass and not emitted (aka, cached). And then symlink all of them from the | ||
// cache folder (where webpack writes) to the output folder | ||
jsonStats.assets.map(function(asset) { | ||
mkdirp.sync(path.dirname(that.outputPath + '/' + asset.name)); | ||
symlinkOrCopySync(that.cachePath + '/' + asset.name, that.outputPath + '/' + asset.name); | ||
}); | ||
resolve(); | ||
} | ||
// Get all of the assets from webpack, both emitted in this current compile | ||
// pass and not emitted (aka, cached). And then symlink all of them from the | ||
// cache folder (where webpack writes) to the output folder | ||
jsonStats.assets.map(function(asset) { | ||
mkdirp.sync(path.dirname(that.outputPath + '/' + asset.name)); | ||
symlinkOrCopySync(that.cachePath + '/' + asset.name, that.outputPath + '/' + asset.name); | ||
}); | ||
resolve(); | ||
}); | ||
@@ -122,0 +125,0 @@ }); |
{ | ||
"name": "broccoli-webpack-cached", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Yet another webpack plugin for Broccoli. This one relies on webpack's caching for speed, but does it in a way that works well as a broccoli plugin (symlinking from the webpack cache to the output folder as needed).", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9178
107