Skip to content

Commit 4027ea0

Browse files
committed
support aplipay build
1 parent d2d69f2 commit 4027ea0

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

index.js

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,35 @@
77
// return typeof global !== 'undefined' ? global : this;
88
// })();
99

10+
const banner = `
11+
if (!global && (typeof my !== 'undefined')) {
12+
var globalModule = require('global');
13+
var Component = globalModule.AFAppX.WorkerComponent;
14+
global = globalModule.AFAppX.$global || {};
15+
}
16+
`;
17+
1018
function mpvueVendorPlugin() {
1119
}
1220

13-
mpvueVendorPlugin.prototype.apply = function (compiler) {
14-
compiler.plugin('emit', (compilation, callback) => {
15-
const fileName = 'common/vendor.js';
16-
const asset = compilation.assets[fileName];
17-
let fileContent = asset.source();
18-
19-
compilation.assets[fileName] = {
20-
source: () => {
21-
let from = /g\s=\s\(function\(\)\s\{\r?\n?\s+return\sthis;\r?\n?\s*\}\)\(\)\;/;
22-
let to = `g = (function() { return typeof global !== 'undefined' ? global : this; })();`
23-
fileContent = fileContent.replace(from, to)
24-
return fileContent;
25-
},
26-
size: () => {
27-
return Buffer.byteLength(fileContent, 'utf8');
28-
}
29-
};
21+
mpvueVendorPlugin.prototype.apply = function(compiler) {
22+
compiler.plugin("emit", (compilation, callback) => {
23+
let regExp = /\.js$/;
24+
let filesName = Object.keys(compilation.assets).filter(name =>
25+
name.match(regExp)
26+
);
27+
filesName.forEach(name => {
28+
let asset = compilation.assets[name];
29+
let fileContent = asset.source();
30+
compilation.assets[name] = {
31+
source: () => {
32+
return banner + "\n" + fileContent;
33+
},
34+
size: () => {
35+
return Buffer.byteLength(fileContent, "utf8");
36+
}
37+
};
38+
});
3039
callback();
3140
});
3241
};

0 commit comments

Comments
 (0)