@@ -5,7 +5,6 @@ const babel = require('babel-core')
55const path = require ( 'path' )
66const fs = require ( 'fs' )
77const deepEqual = require ( 'deep-equal' )
8- const relative = require ( '../utils/relative' )
98
109const { parseConfig, parseComponentsDeps, parseGlobalComponents, clearGlobalComponents } = require ( './parse' )
1110const { parseComponentsDeps : parseComponentsDepsTs } = require ( './parse-ts' )
@@ -27,10 +26,9 @@ let slotsHookAdded = false
2726
2827// 调用 compiler 生成 wxml
2928function genComponentWxml ( compiled , options , emitFile , emitError , emitWarning ) {
30- options . components [ 'slots' ] = { src : 'slots' , name : 'slots' }
29+ options . components [ 'slots' ] = { src : '/components/ slots' , name : 'slots' }
3130 const { code : wxmlCodeStr , compiled : cp , slots, importCode } = compiler . compileToWxml ( compiled , options )
3231 const { mpErrors, mpTips } = cp
33-
3432 // 缓存 slots,延迟编译
3533 cacheSlots ( slots , importCode )
3634
@@ -51,7 +49,7 @@ function genComponentWxml (compiled, options, emitFile, emitError, emitWarning)
5149function createAppWxml ( emitFile , resourcePath , rootComponent , context ) {
5250 const { src } = getFileInfo ( resourcePath ) || { }
5351 const { name : componentName , filePath : wxmlSrc } = getCompNameAndSrc ( context , rootComponent )
54- const wxmlContent = genPageWxml ( componentName , relative ( `/ ${ src } .wxml` , `/ ${ wxmlSrc } ` ) )
52+ const wxmlContent = genPageWxml ( componentName , wxmlSrc )
5553 emitFile ( `${ src } .wxml` , wxmlContent )
5654}
5755// 更新全局组件时,需要重新生成wxml,用这个字段保存所有需要更新的页面及其参数
@@ -118,12 +116,13 @@ function compileWxml (compiled, html) {
118116// 针对 .vue 单文件的脚本逻辑的处理
119117// 处理出当前单文件组件的子组件依赖
120118function compileMPScript ( script , mpOptioins , moduleId ) {
119+ const { resourcePath, options, resolve, context } = this
121120 const babelrc = getBabelrc ( mpOptioins . globalBabelrc )
122121 let result , metadata
123122 let scriptContent = script . content
124123 const babelOptions = { extends : babelrc , plugins : [ parseComponentsDeps ] }
125124 if ( script . src ) { // 处理src
126- const scriptpath = path . join ( path . dirname ( this . resourcePath ) , script . src )
125+ const scriptpath = path . join ( path . dirname ( resourcePath ) , script . src )
127126 scriptContent = fs . readFileSync ( scriptpath ) . toString ( )
128127 }
129128 if ( script . lang === 'ts' ) { // 处理ts
@@ -138,16 +137,16 @@ function compileMPScript (script, mpOptioins, moduleId) {
138137
139138 // 处理子组件的信息
140139 const components = { }
141- const fileInfo = resolveTarget ( this . resourcePath , this . options . entry )
140+ const fileInfo = resolveTarget ( resourcePath , options . entry )
142141 if ( originComponents ) {
143- resolveSrc ( originComponents , components , this . resolve , this . context ) . then ( ( ) => {
144- resolveComponent ( this . resourcePath , fileInfo , importsMap , components , moduleId )
142+ resolveSrc ( originComponents , components , resolve , context , options . context ) . then ( ( ) => {
143+ resolveComponent ( resourcePath , fileInfo , importsMap , components , moduleId )
145144 } ) . catch ( err => {
146145 console . error ( err )
147- resolveComponent ( this . resourcePath , fileInfo , importsMap , components , moduleId )
146+ resolveComponent ( resourcePath , fileInfo , importsMap , components , moduleId )
148147 } )
149148 } else {
150- resolveComponent ( this . resourcePath , fileInfo , importsMap , components , moduleId )
149+ resolveComponent ( resourcePath , fileInfo , importsMap , components , moduleId )
151150 }
152151
153152 return script
@@ -183,7 +182,7 @@ function compileMP (content, mpOptioins) {
183182
184183 // 解析全局组件的路径
185184 const components = { }
186- resolveSrc ( globalComps , components , resolve , context ) . then ( ( ) => {
185+ resolveSrc ( globalComps , components , resolve , context , options . context ) . then ( ( ) => {
187186 handleResult ( components )
188187 } ) . catch ( err => {
189188 console . error ( err )
@@ -220,13 +219,13 @@ function compileMP (content, mpOptioins) {
220219 return content
221220}
222221
223- function resolveSrc ( originComponents , components , resolveFn , context ) {
222+ function resolveSrc ( originComponents , components , resolveFn , context , projectRoot ) {
224223 return Promise . all ( Object . keys ( originComponents ) . map ( k => {
225224 return new Promise ( ( resolve , reject ) => {
226225 resolveFn ( context , originComponents [ k ] , ( err , realSrc ) => {
227226 if ( err ) return reject ( err )
228227 const com = covertCCVar ( k )
229- const { filePath, name } = getCompNameAndSrc ( context , realSrc )
228+ const { filePath, name } = getCompNameAndSrc ( projectRoot , realSrc )
230229 components [ com ] = { src : filePath , name }
231230 resolve ( )
232231 } )
0 commit comments