apply-loader
Advanced tools
Comparing version 1.0.0 to 2.0.0
29
index.js
@@ -5,3 +5,3 @@ var loaderUtils = require("loader-utils"); | ||
module.exports.pitch = function applyLoader(remainingRequest) { | ||
var query = loaderUtils.parseQuery(this.query); | ||
var opts = loaderUtils.getOptions(this) || {}; | ||
var args = []; | ||
@@ -11,19 +11,16 @@ | ||
// apply?config=key => sourceFn(require('webpack.config').key) | ||
if (typeof query.config === "string") { | ||
if (!(query.config in this.options)) | ||
throw new Error("apply-loader: '"+query.config+"' property not present in webpack config"); | ||
args.push(this.options[query.config]); | ||
if (typeof opts.config === "string") { | ||
// apply?config=key => sourceFn(require('webpack.config').key) | ||
if (!(opts.config in this.options)) { | ||
throw new Error("apply-loader: '"+opts.config+"' property not present in webpack config"); | ||
} | ||
args.push(this.options[opts.config]); | ||
} else if (Array.isArray(opts.args)) { | ||
// apply?args[]=1&args[]=2 => sourceFn(1, 2) | ||
args.push.apply(args, opts.args); | ||
} else if (opts.obj) { | ||
// apply?{obj: {a: 1, b: 2}} => sourceFn({a: 1, b:2}) | ||
args.push(opts.obj); | ||
} | ||
// apply?{obj: {a: 1, b: 2}} => sourceFn({a: 1, b:2}) | ||
if (query.obj) { | ||
args.push(query.obj); | ||
} | ||
// apply?args[]=1&args[]=2 => sourceFn(1, 2) | ||
if (Array.isArray(query.args)) { | ||
args.push.apply(args, query.args); | ||
} | ||
return [ | ||
@@ -30,0 +27,0 @@ "var req = require(", |
{ | ||
"name": "apply-loader", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Apply loader for webpack", | ||
@@ -11,2 +11,9 @@ "main": "index.js", | ||
}, | ||
"maintainers": [ | ||
{ | ||
"name": "mogelbrod", | ||
"email": "victor@hallberg.cc" | ||
} | ||
], | ||
"homepage": "https://github.com/mogelbrod/apply-loader#readme", | ||
"repository": { | ||
@@ -16,5 +23,8 @@ "type": "git", | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/mogelbrod/apply-loader/issues" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"loader-utils": "~0.2.6" | ||
"loader-utils": "^1.1.0" | ||
}, | ||
@@ -21,0 +31,0 @@ "keywords": [ |
@@ -7,4 +7,6 @@ # apply loader for webpack | ||
The `apply` loader can be used to execute a JavaScript function exported, optionally with arguments, and export the returned value. | ||
The `apply` loader can be used to execute an exported JavaScript function (optionally with arguments) and export the returned value. | ||
It will attempt to call the `default` export if defined, falling back to the basic export (i.e. `module.exports`). | ||
``` javascript | ||
@@ -24,4 +26,20 @@ // Call with multiple arguments | ||
## Webpack 2 configuration | ||
``` javascript | ||
use: [{ | ||
loader: 'apply-loader', | ||
options: { | ||
// => sourceFn({a: 1}, true) | ||
args: [ {a: 1}, true ] | ||
// => sourceFn({a: 1}) | ||
obj: {a: 1} | ||
// => sourceFn(require('webpack.config').customConfig) | ||
config: 'customConfig' | ||
} | ||
} | ||
``` | ||
## License | ||
MIT (http://www.opensource.org/licenses/mit-license.php) |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
3954
1
0
44
28
+ Addedbig.js@5.2.2(transitive)
+ Addedemojis-list@3.0.0(transitive)
+ Addedjson5@1.0.2(transitive)
+ Addedloader-utils@1.4.2(transitive)
+ Addedminimist@1.2.8(transitive)
- Removedbig.js@3.2.0(transitive)
- Removedemojis-list@2.1.0(transitive)
- Removedjson5@0.5.1(transitive)
- Removedloader-utils@0.2.17(transitive)
- Removedobject-assign@4.1.1(transitive)
Updatedloader-utils@^1.1.0