From 0af8b2f1e779ffa71a58e71e49a92edb263e5d7d Mon Sep 17 00:00:00 2001 From: yangtianjie Date: Wed, 30 Dec 2020 16:42:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20loader=20asset=E4=B8=8D=E5=8F=98?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/loader/replace-loader.js | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 1acf44a..4fe0b33 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mpbuild", - "version": "4.0.4", + "version": "4.0.5", "description": "", "main": "src/index.js", "scripts": { diff --git a/src/loader/replace-loader.js b/src/loader/replace-loader.js index f93f581..027c2e5 100644 --- a/src/loader/replace-loader.js +++ b/src/loader/replace-loader.js @@ -1,12 +1,15 @@ /** * Created by ximing on 2019-03-14. */ +const obj = {}; + module.exports = function (opts) { let { search, replacement } = opts; return function replaceLoader(asset) { if (typeof replacement === 'function') { // Pass the vinyl file object as this.file - replacement = replacement.bind({ asset }); + obj.asset = asset; + replacement = replacement.bind(obj); } if (search instanceof RegExp) { asset.contents = asset.contents.replace(search, replacement); @@ -28,4 +31,4 @@ module.exports = function (opts) { } return asset; }; -}; +}; \ No newline at end of file