diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-02-18 15:27:06 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-02-18 15:27:06 +0900 |
| commit | 62fd58fbc8e7c0ed3ab8452c66694920793abe15 (patch) | |
| tree | 2fe7298149458a9061882f2d311c78fe75658733 /webpack/loaders/replace.js | |
| parent | wip (diff) | |
| download | misskey-62fd58fbc8e7c0ed3ab8452c66694920793abe15.tar.gz misskey-62fd58fbc8e7c0ed3ab8452c66694920793abe15.tar.bz2 misskey-62fd58fbc8e7c0ed3ab8452c66694920793abe15.zip | |
wip
Diffstat (limited to 'webpack/loaders/replace.js')
| -rw-r--r-- | webpack/loaders/replace.js | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/webpack/loaders/replace.js b/webpack/loaders/replace.js index 4bb00a2abf..03cf1fcd78 100644 --- a/webpack/loaders/replace.js +++ b/webpack/loaders/replace.js @@ -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; }; |