Skip to content

Commit

Permalink
fix: loader asset不变的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yangtianjie committed Dec 30, 2020
1 parent ecf68bf commit 0af8b2f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mpbuild",
"version": "4.0.4",
"version": "4.0.5",
"description": "",
"main": "src/index.js",
"scripts": {
Expand Down
7 changes: 5 additions & 2 deletions src/loader/replace-loader.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -28,4 +31,4 @@ module.exports = function (opts) {
}
return asset;
};
};
};

0 comments on commit 0af8b2f

Please sign in to comment.