rev-replace-loader
Advanced tools
Comparing version 0.2.0 to 0.3.0
# CHANGELOG | ||
## 0.3.0 | ||
- Added support for prefix in search queries | ||
## 0.2.0 | ||
- Add support for globbing of file paths | ||
- Added support for globbing of file paths |
45
index.js
@@ -6,32 +6,35 @@ var path = require('path'); | ||
module.exports = function (source) { | ||
var query = loaderUtils.parseQuery(this.query); | ||
var manifest = query.manifest || (query.manifestPath ? requireManifests(query.manifestPath) : false); | ||
var query = loaderUtils.parseQuery(this.query); | ||
var manifest = query.manifest || (query.manifestPath ? requireManifests(query.manifestPath) : false); | ||
var prefix = query.prefix || ''; | ||
if (manifest) { | ||
for (var key in manifest) { | ||
var value = manifest[key]; | ||
var pattern = new RegExp(key, 'gm'); | ||
source = source.replace(pattern, value); | ||
if (manifest) { | ||
for (var key in manifest) { | ||
if (manifest.hasOwnProperty(key)) { | ||
var value = manifest[key]; | ||
var pattern = new RegExp(prefix + key, 'gm'); | ||
source = source.replace(pattern, value); | ||
} | ||
} | ||
} | ||
} | ||
return source; | ||
return source; | ||
}; | ||
function requireManifests(manifestGlob) { | ||
return glob.sync(manifestGlob).map(function (path) { | ||
return requireManifest(path); | ||
}).filter(function (manifest) { | ||
return manifest !== false; | ||
}).reduce(function (manifest, current) { | ||
return Object.assign(manifest, current); | ||
}, {}); | ||
return glob.sync(manifestGlob).map(function (path) { | ||
return requireManifest(path); | ||
}).filter(function (manifest) { | ||
return manifest !== false; | ||
}).reduce(function (manifest, current) { | ||
return Object.assign(manifest, current); | ||
}, {}); | ||
} | ||
function requireManifest(manifestPath) { | ||
try { | ||
return require(path.resolve(process.cwd(), manifestPath)); | ||
} catch (error) { | ||
return false; | ||
} | ||
try { | ||
return require(path.resolve(process.cwd(), manifestPath)); | ||
} catch (error) { | ||
return false; | ||
} | ||
} |
{ | ||
"name": "rev-replace-loader", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Webpack loader to replace asset paths with hashed ones from a rev-manifest.json file", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"type": "git", | ||
"url": "git://github.com/vigetlabs/rev-replace-loader.git" | ||
"url": "git://github.com/bushee/rev-replace-loader.git" | ||
}, | ||
@@ -11,0 +11,0 @@ "keywords": [ |
@@ -25,16 +25,19 @@ Replace rev'd asset references in your production JS compiled with Webpack! | ||
There is optional `prefix` parameter - if given, it will be prepended to all queries to be replaced. | ||
```js | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.jsx?$/, | ||
loader: 'rev-replace', | ||
query: { | ||
manifest: require('path/to/manifest'), | ||
manifestPath: 'path/to/manifest' | ||
} | ||
} | ||
] | ||
} | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.jsx?$/, | ||
loader: 'rev-replace', | ||
query: { | ||
manifest: require('path/to/manifest'), | ||
manifestPath: 'path/to/manifest', | ||
prefix: '/' | ||
} | ||
} | ||
] | ||
} | ||
} | ||
``` |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
43547
13
34
43