@@ -17,6 +17,13 @@ const traverse = _traverse.default ? _traverse.default : _traverse
1717
1818const fileType = [ '.wxml' , '.ddml' ]
1919
20+ // Babel 统一配置,确保跨平台编译一致性
21+ const BABEL_TRANSFORM_CONFIG = {
22+ comments : false ,
23+ sourceType : 'script' ,
24+ configFile : false ,
25+ }
26+
2027// 页面文件编译内容缓存
2128const compileResCache = new Map ( )
2229
@@ -343,10 +350,7 @@ function compileModule(module, isComponent, scriptRes) {
343350
344351 const ast = babel . parseSync ( code )
345352 insertWxsToRenderAst ( ast , instruction . scriptModule , scriptRes )
346- code = babel . transformFromAstSync ( ast , '' , {
347- comments : false ,
348- sourceType : 'script'
349- } ) . code
353+ code = babel . transformFromAstSync ( ast , '' , BABEL_TRANSFORM_CONFIG ) . code
350354
351355 tplComponents
352356 += `'${ tm . path } ':${ cleanCompiledCode ( code ) } ,`
@@ -355,10 +359,7 @@ function compileModule(module, isComponent, scriptRes) {
355359
356360 const tplAst = babel . parseSync ( tplCode . code )
357361 insertWxsToRenderAst ( tplAst , instruction . scriptModule , scriptRes )
358- const { code : transCode } = babel . transformFromAstSync ( tplAst , '' , {
359- comments : false ,
360- sourceType : 'script'
361- } )
362+ const { code : transCode } = babel . transformFromAstSync ( tplAst , '' , BABEL_TRANSFORM_CONFIG )
362363
363364 // 通过 component 字段标记该页面 以 Component 形式进行渲染或着以 Page 形式进行渲染
364365 // https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/page.html
@@ -567,10 +568,7 @@ function processWxsContent(wxsContent, wxsFilePath, scriptModule, workPath, file
567568 } )
568569
569570 // 生成代码
570- return babel . transformFromAstSync ( wxsAst , '' , {
571- comments : false ,
572- sourceType : 'script'
573- } ) . code
571+ return babel . transformFromAstSync ( wxsAst , '' , BABEL_TRANSFORM_CONFIG ) . code
574572}
575573
576574/**
@@ -673,10 +671,7 @@ function compileModuleWithAllWxs(module, scriptRes, allScriptModules) {
673671
674672 const ast = babel . parseSync ( code )
675673 insertWxsToRenderAst ( ast , allScriptModules , scriptRes )
676- code = babel . transformFromAstSync ( ast , '' , {
677- comments : false ,
678- sourceType : 'script'
679- } ) . code
674+ code = babel . transformFromAstSync ( ast , '' , BABEL_TRANSFORM_CONFIG ) . code
680675
681676 tplComponents
682677 += `'${ tm . path } ':${ cleanCompiledCode ( code ) } ,`
@@ -685,10 +680,7 @@ function compileModuleWithAllWxs(module, scriptRes, allScriptModules) {
685680
686681 const tplAst = babel . parseSync ( tplCode . code )
687682 insertWxsToRenderAst ( tplAst , allScriptModules , scriptRes )
688- const { code : transCode } = babel . transformFromAstSync ( tplAst , '' , {
689- comments : false ,
690- sourceType : 'script'
691- } )
683+ const { code : transCode } = babel . transformFromAstSync ( tplAst , '' , BABEL_TRANSFORM_CONFIG )
692684
693685 const code = `Module({
694686 path: '${ module . path } ',
0 commit comments