Skip to content

Commit 60603e6

Browse files
committed
add and expose createTarget function
1 parent dc30132 commit 60603e6

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/index.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,28 @@ const stripExt = path => {
3030
return join(dir, name);
3131
};
3232

33-
const miniProgramTarget = compiler => {
34-
const { options } = compiler;
35-
compiler.apply(
36-
new JsonpTemplatePlugin(options.output),
37-
new FunctionModulePlugin(options.output),
38-
new NodeSourcePlugin(options.node),
39-
new LoaderTargetPlugin('web')
33+
export const createTarget = function createTarget(name) {
34+
const miniProgramTarget = compiler => {
35+
const { options } = compiler;
36+
compiler.apply(
37+
new JsonpTemplatePlugin(options.output),
38+
new FunctionModulePlugin(options.output),
39+
new NodeSourcePlugin(options.node),
40+
new LoaderTargetPlugin('web')
41+
);
42+
};
43+
44+
// eslint-disable-next-line no-new-func
45+
const creater = new Function(
46+
`var t = arguments[0]; return function ${name}(c) { return t(c); }`
4047
);
48+
return creater(miniProgramTarget);
4149
};
4250

4351
export const Targets = {
44-
Wechat(compiler) {
45-
return miniProgramTarget(compiler);
46-
},
47-
Alipay(compiler) {
48-
return miniProgramTarget(compiler);
49-
}
52+
Wechat: createTarget('Wechat'),
53+
Alipay: createTarget('Alipay'),
54+
Baidu: createTarget('Baidu')
5055
};
5156

5257
export default class WXAppPlugin {

0 commit comments

Comments
 (0)