grunt-webpack
Advanced tools
Comparing version 0.4.0 to 0.9.0
{ | ||
"name": "grunt-webpack", | ||
"description": "Use webpack with grunt.", | ||
"version": "0.4.0", | ||
"version": "0.9.0", | ||
"homepage": "https://github.com/webpack/grunt-webpack", | ||
@@ -17,4 +17,3 @@ "author": { | ||
"dependencies": { | ||
"webpack": "0.7.x", | ||
"sprintf": "0.1.x" | ||
"webpack": "0.9.x" | ||
}, | ||
@@ -21,0 +20,0 @@ "licenses": [ |
# grunt-webpack | ||
Use [modules-webpack](https://github.com/sokra/modules-webpack/) with grunt. | ||
Use [webpack](https://github.com/webpack/webpack) with grunt. | ||
@@ -19,8 +19,8 @@ ## Getting Started | ||
someName: { | ||
src: "client/lib/index.js", | ||
dest: "asserts/[hash].js", | ||
// all other webpack options here: | ||
publicPrefix: "asserts/", // i.e. | ||
// one extra option for grunt-webpack | ||
statsTarget: "xyz", // writes the status to a variable named xyz | ||
entry: "./client/lib/index.js", | ||
output: { | ||
path: "asserts/", | ||
filename: "[hash].js", | ||
}, | ||
storeStatsTo: "xyz", // writes the status to a variable named xyz | ||
// you may use it later in grunt i.e. <%= xyz.hash %> | ||
@@ -32,3 +32,3 @@ }, | ||
`grunt-webpack` uses the [programmatically interface](https://github.com/sokra/modules-webpack#programmatically-usage). | ||
`grunt-webpack` uses the [webpack options](https://github.com/webpack/docs/wiki/webpack-options). | ||
@@ -38,3 +38,3 @@ The `watch` option is not valid for compiling with `grunt`, you have to use the watch function of grunt. | ||
## License | ||
Copyright (c) 2012 Tobias Koppers @sokra | ||
Copyright (c) 2012-2013 Tobias Koppers @sokra | ||
Licensed under the MIT license. |
@@ -10,8 +10,9 @@ /* | ||
var path = require("path"); | ||
var sprintf = require("sprintf").sprintf; | ||
module.exports = function(grunt) { | ||
var webpack = require("webpack"); | ||
var CachePlugin = require("webpack/lib/CachePlugin"); | ||
var ProgressPlugin = require("webpack/lib/ProgressPlugin"); | ||
var theCache = new (require("webpack/lib/Cache"))(); | ||
var theCachePlugin = new CachePlugin(); | ||
@@ -23,73 +24,58 @@ grunt.registerMultiTask('webpack', 'Webpack files.', function() { | ||
var options = Object.create(this.data); | ||
var input = path.join(process.cwd(), grunt.template.process(options.src)); | ||
var output = path.join(process.cwd(), grunt.template.process(options.dest)); | ||
var statsTarget = options.statsTarget; | ||
options.context = options.context ? | ||
path.resolve(process.cwd(), grunt.template.process(options.context)) : | ||
process.cwd(); | ||
if(options.output) { | ||
options.output.path = options.output.path ? | ||
path.resolve(process.cwd(), grunt.template.process(options.output.path)) : | ||
process.cwd(); | ||
} | ||
// Default values | ||
if(!options.outputDirectory) options.outputDirectory = path.dirname(output); | ||
if(!options.output) options.output = path.basename(output); | ||
if(!options.outputPostfix) options.outputPostfix = "." + path.basename(output); | ||
if(!options.events) options.events = new (require("events").EventEmitter)(); | ||
if(!options.cache) options.cache = theCache; | ||
var cache = options.cache; | ||
options.cache = false; | ||
var storeStatsTo = options.storeStatsTo; | ||
var compiler = webpack(options); | ||
var events = options.events; | ||
var sum = 0; | ||
var finished = 0; | ||
if(cache) | ||
compiler.apply(theCachePlugin); | ||
var chars = 0; | ||
function print() { | ||
var msg = ""; | ||
if(sum > 0) { | ||
msg += "compiling... ("; | ||
msg += String(sprintf("%4s", finished+"") + "/" + sprintf("%4s", sum+"")).yellow.bold; | ||
msg += String(" " + sprintf("%4s", Math.floor(finished*100/sum)+"%")).yellow.bold; | ||
msg += ")"; | ||
compiler.apply(new ProgressPlugin(function(percentage, msg) { | ||
if(percentage < 1) { | ||
percentage = Math.floor(percentage * 100); | ||
msg = percentage + "% " + msg; | ||
if(percentage < 100) msg = " " + msg; | ||
if(percentage < 10) msg = " " + msg; | ||
} | ||
for(; chars > msg.length; chars--) | ||
grunt.log.write("\b \b"); | ||
chars = msg.length; | ||
for(var i = 0; i < chars; i++) | ||
grunt.log.write("\b"); | ||
grunt.log.write(msg); | ||
chars = msg.length; | ||
} | ||
var taskListener, taskEndListener, bundleListener; | ||
events.on("task", taskListener = function(name) { | ||
sum++; | ||
print(); | ||
}); | ||
events.on("task-end", taskEndListener = function(name) { | ||
finished++; | ||
if(name) { | ||
for(var i = 0; i < chars; i++) | ||
grunt.log.write("\b \b"); | ||
grunt.log.writeln(name + " " + "done".green.bold); | ||
chars = 0; | ||
} | ||
print(); | ||
}); | ||
events.on("bundle", bundleListener = function(name) { | ||
sum = 0; | ||
finished = 0; | ||
for(var i = 0; i < chars; i++) | ||
grunt.log.write("\b \b"); | ||
chars = 0; | ||
}); | ||
webpack(input, options, function(err, stats) { | ||
events.removeListener("task", taskListener); | ||
events.removeListener("task-end", taskEndListener); | ||
events.removeListener("bundle", bundleListener); | ||
})); | ||
compiler.run(function(err, stats) { | ||
if(err) { | ||
grunt.log.error(err); | ||
done(false); | ||
return done(false); | ||
} | ||
if(stats.warnings) | ||
stats.warnings.forEach(grunt.log.writeln.bind(grunt.log)); | ||
if(stats.errors) | ||
stats.errors.forEach(grunt.warn); | ||
if(statsTarget) { | ||
var st; | ||
if(typeof statsTarget === "string") | ||
st = statsTarget; | ||
else if(statsTarget) | ||
st = statsTarget[index]; | ||
if(st) | ||
grunt.config.set(st, stats); | ||
grunt.log.notverbose.writeln(stats.toString({ | ||
colors: true, | ||
hash: false, | ||
timings: false, | ||
assets: true, | ||
chunks: false, | ||
chunkModules: false, | ||
modules: false, | ||
children: true | ||
})); | ||
grunt.verbose.writeln(stats.toString({ | ||
colors: true | ||
})); | ||
if(typeof storeStatsTo === "string") { | ||
grunt.config.set(storeStatsTo, stats.toJson()); | ||
} | ||
if(options.failOnError && stats.hasErrors()) | ||
return done(false); | ||
done(); | ||
@@ -96,0 +82,0 @@ }); |
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
1
4928
73
+ Addedamdefine@1.0.1(transitive)
+ Addedasync@0.2.10(transitive)
+ Addedbase64-js@0.0.2(transitive)
+ Addedbuffer-browserify@0.0.4(transitive)
+ Addedclone@0.1.19(transitive)
+ Addedconcat-stream@0.0.8(transitive)
+ Addedconsole-browserify@0.1.6(transitive)
+ Addedcrypto-browserify@0.2.1(transitive)
+ Addedenhanced-resolve@0.5.15(transitive)
+ Addedesprima@1.0.4(transitive)
+ Addedhttp-browserify@0.1.6(transitive)
+ Addednode-libs-browser@0.1.2(transitive)
+ Addedoptimist@0.3.7(transitive)
+ Addedsource-map@0.1.43(transitive)
+ Addedtapable@0.1.10(transitive)
+ Addeduglify-js@2.2.5(transitive)
+ Addedvm-browserify@0.0.1(transitive)
+ Addedwebpack@0.9.3(transitive)
+ Addedwebpack-core@0.1.5(transitive)
+ Addedzlib-browserify@0.0.1(transitive)
- Removedsprintf@0.1.x
- Removedbundle-loader@0.2.0(transitive)
- Removedcoffee-loader@0.2.0(transitive)
- Removedcoffee-script@1.12.71.4.0(transitive)
- Removedcommander@0.6.1(transitive)
- Removedcss-loader@0.2.4(transitive)
- Removedcsso@1.2.18(transitive)
- Removedenhanced-require@0.3.1(transitive)
- Removedenhanced-resolve@0.2.90.3.1(transitive)
- Removedesprima@0.9.9(transitive)
- Removedfile-loader@0.1.2(transitive)
- Removedjade@0.27.7(transitive)
- Removedjade-loader@0.2.3(transitive)
- Removedjson-loader@0.2.0(transitive)
- Removedjson5@0.1.0(transitive)
- Removedless@1.3.3(transitive)
- Removedless-loader@0.2.2(transitive)
- Removedloader-utils@0.1.2(transitive)
- Removedoptimist@0.2.8(transitive)
- Removedraw-loader@0.1.60.2.0(transitive)
- Removedscript-loader@0.2.1(transitive)
- Removedsprintf@0.1.5(transitive)
- Removedstyle-loader@0.2.1(transitive)
- Removeduglify-js@1.2.6(transitive)
- Removedval-loader@0.1.2(transitive)
- Removedwebpack@0.7.17(transitive)
- Removedycssmin@1.0.1(transitive)
Updatedwebpack@0.9.x