This commit is contained in:
syuilo 2018-05-17 19:38:20 +09:00
parent b2368b04db
commit 90a4fe471d
3 changed files with 33 additions and 32 deletions

View File

@ -209,7 +209,7 @@
"vue-cropperjs": "2.2.0",
"vue-js-modal": "1.3.13",
"vue-json-tree-view": "2.1.4",
"vue-loader": "15.0.5",
"vue-loader": "15.0.11",
"vue-router": "3.0.1",
"vue-template-compiler": "2.5.16",
"vuedraggable": "2.16.0",

View File

@ -146,27 +146,20 @@ module.exports = {
}, {
loader: 'replace',
query: {
qs: [{
search: /%base64:(.+?)%/g.toString(),
replace: 'base64replacement'
}
}, {
loader: 'replace',
query: {
search: i18nPattern.toString(),
replace: 'i18nReplacement',
i18n: true
}
}, {
loader: 'replace',
query: {
search: faPattern.toString(),
replace: 'faReplacement'
}
}, {
loader: 'replace',
query: {
search: /^<template>([\s\S]+?)\r?\n<\/template>/.toString(),
replace: 'collapseSpacesReplacement'
}]
}
}]
}, {

View File

@ -5,8 +5,7 @@ function trim(text, g) {
}
export default function(src) {
this.cacheable();
const options = getOptions(this);
const fn = options => {
const search = options.search;
const g = search[search.length - 1] == 'g';
const file = this.resourcePath.replace(/\\/g, '/');
@ -17,6 +16,15 @@ export default function(src) {
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), g ? 'g' : ''), replace);
};
this.cacheable();
const options = getOptions(this);
if (options.qs) {
options.qs.forEach(q => fn(q));
} else {
fn(options);
}
this.callback(null, src);
return src;
}