@@ -30,23 +30,28 @@ const stripExt = path => {
30
30
return join ( dir , name ) ;
31
31
} ;
32
32
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); }`
40
47
) ;
48
+ return creater ( miniProgramTarget ) ;
41
49
} ;
42
50
43
51
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' )
50
55
} ;
51
56
52
57
export default class WXAppPlugin {
0 commit comments