wip
This commit is contained in:
parent
a7601f7aa4
commit
085ac938c2
6 changed files with 28 additions and 8 deletions
15
webpack/loaders/replace.js
Normal file
15
webpack/loaders/replace.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
const loaderUtils = require('loader-utils');
|
||||
|
||||
function trim(text) {
|
||||
return text.substring(1, text.length - 2);
|
||||
}
|
||||
|
||||
module.exports = function(src) {
|
||||
this.cacheable();
|
||||
const options = loaderUtils.getOptions(this);
|
||||
if (typeof options.search != 'string' || options.search.length == 0) console.error('invalid search');
|
||||
if (typeof options.replace != 'function') console.error('invalid replacer');
|
||||
src = src.replace(new RegExp(trim(options.search), 'g'), options.replace);
|
||||
this.callback(null, src);
|
||||
return src;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue