wip
This commit is contained in:
parent
2f3f97a12c
commit
62fd58fbc8
5 changed files with 41 additions and 19 deletions
|
@ -1,17 +1,18 @@
|
|||
const loaderUtils = require('loader-utils');
|
||||
|
||||
function trim(text) {
|
||||
return text.substring(1, text.length - 2);
|
||||
function trim(text, g) {
|
||||
return text.substring(1, text.length - (g ? 2 : 0));
|
||||
}
|
||||
|
||||
module.exports = function(src) {
|
||||
this.cacheable();
|
||||
const options = loaderUtils.getOptions(this);
|
||||
const search = options.search;
|
||||
const g = search[search.length - 1] == 'g';
|
||||
const replace = global[options.replace];
|
||||
if (typeof search != 'string' || search.length == 0) console.error('invalid search');
|
||||
if (typeof replace != 'function') console.error('invalid replacer:', replace, this.request);
|
||||
src = src.replace(new RegExp(trim(search), 'g'), replace);
|
||||
src = src.replace(new RegExp(trim(search, g), g ? 'g' : ''), replace);
|
||||
this.callback(null, src);
|
||||
return src;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue