diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-05-17 19:38:20 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-05-17 19:38:20 +0900 |
| commit | 90a4fe471d06a4a0b598d947caff2ddd69d1ed5b (patch) | |
| tree | b60c544a60ddc737139e487415e14a02826f5efd /webpack | |
| parent | 2.7.0 (diff) | |
| download | sharkey-90a4fe471d06a4a0b598d947caff2ddd69d1ed5b.tar.gz sharkey-90a4fe471d06a4a0b598d947caff2ddd69d1ed5b.tar.bz2 sharkey-90a4fe471d06a4a0b598d947caff2ddd69d1ed5b.zip | |
:v:
Diffstat (limited to 'webpack')
| -rw-r--r-- | webpack/loaders/replace.js | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/webpack/loaders/replace.js b/webpack/loaders/replace.js index d8a81c245a..fd6bb3617b 100644 --- a/webpack/loaders/replace.js +++ b/webpack/loaders/replace.js @@ -5,18 +5,26 @@ function trim(text, g) { } export default function(src) { + const fn = options => { + const search = options.search; + const g = search[search.length - 1] == 'g'; + const file = this.resourcePath.replace(/\\/g, '/'); + const replace = options.i18n ? global[options.replace].bind(null, { + src: file, + lang: options.lang + }) : 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), g ? 'g' : ''), replace); + }; + this.cacheable(); const options = getOptions(this); - const search = options.search; - const g = search[search.length - 1] == 'g'; - const file = this.resourcePath.replace(/\\/g, '/'); - const replace = options.i18n ? global[options.replace].bind(null, { - src: file, - lang: options.lang - }) : 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), g ? 'g' : ''), replace); + if (options.qs) { + options.qs.forEach(q => fn(q)); + } else { + fn(options); + } this.callback(null, src); return src; } |