@@ -5,7 +5,6 @@ const babel = require('babel-core')
5
5
const path = require ( 'path' )
6
6
const fs = require ( 'fs' )
7
7
const deepEqual = require ( 'deep-equal' )
8
- const relative = require ( '../utils/relative' )
9
8
10
9
const { parseConfig, parseComponentsDeps, parseGlobalComponents, clearGlobalComponents } = require ( './parse' )
11
10
const { parseComponentsDeps : parseComponentsDepsTs } = require ( './parse-ts' )
@@ -27,10 +26,9 @@ let slotsHookAdded = false
27
26
28
27
// 调用 compiler 生成 wxml
29
28
function genComponentWxml ( compiled , options , emitFile , emitError , emitWarning ) {
30
- options . components [ 'slots' ] = { src : 'slots' , name : 'slots' }
29
+ options . components [ 'slots' ] = { src : '/components/ slots' , name : 'slots' }
31
30
const { code : wxmlCodeStr , compiled : cp , slots, importCode } = compiler . compileToWxml ( compiled , options )
32
31
const { mpErrors, mpTips } = cp
33
-
34
32
// 缓存 slots,延迟编译
35
33
cacheSlots ( slots , importCode )
36
34
@@ -51,7 +49,7 @@ function genComponentWxml (compiled, options, emitFile, emitError, emitWarning)
51
49
function createAppWxml ( emitFile , resourcePath , rootComponent , context ) {
52
50
const { src } = getFileInfo ( resourcePath ) || { }
53
51
const { name : componentName , filePath : wxmlSrc } = getCompNameAndSrc ( context , rootComponent )
54
- const wxmlContent = genPageWxml ( componentName , relative ( `/ ${ src } .wxml` , `/ ${ wxmlSrc } ` ) )
52
+ const wxmlContent = genPageWxml ( componentName , wxmlSrc )
55
53
emitFile ( `${ src } .wxml` , wxmlContent )
56
54
}
57
55
// 更新全局组件时,需要重新生成wxml,用这个字段保存所有需要更新的页面及其参数
@@ -118,12 +116,13 @@ function compileWxml (compiled, html) {
118
116
// 针对 .vue 单文件的脚本逻辑的处理
119
117
// 处理出当前单文件组件的子组件依赖
120
118
function compileMPScript ( script , mpOptioins , moduleId ) {
119
+ const { resourcePath, options, resolve, context } = this
121
120
const babelrc = getBabelrc ( mpOptioins . globalBabelrc )
122
121
let result , metadata
123
122
let scriptContent = script . content
124
123
const babelOptions = { extends : babelrc , plugins : [ parseComponentsDeps ] }
125
124
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 )
127
126
scriptContent = fs . readFileSync ( scriptpath ) . toString ( )
128
127
}
129
128
if ( script . lang === 'ts' ) { // 处理ts
@@ -138,16 +137,16 @@ function compileMPScript (script, mpOptioins, moduleId) {
138
137
139
138
// 处理子组件的信息
140
139
const components = { }
141
- const fileInfo = resolveTarget ( this . resourcePath , this . options . entry )
140
+ const fileInfo = resolveTarget ( resourcePath , options . entry )
142
141
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 )
145
144
} ) . catch ( err => {
146
145
console . error ( err )
147
- resolveComponent ( this . resourcePath , fileInfo , importsMap , components , moduleId )
146
+ resolveComponent ( resourcePath , fileInfo , importsMap , components , moduleId )
148
147
} )
149
148
} else {
150
- resolveComponent ( this . resourcePath , fileInfo , importsMap , components , moduleId )
149
+ resolveComponent ( resourcePath , fileInfo , importsMap , components , moduleId )
151
150
}
152
151
153
152
return script
@@ -183,7 +182,7 @@ function compileMP (content, mpOptioins) {
183
182
184
183
// 解析全局组件的路径
185
184
const components = { }
186
- resolveSrc ( globalComps , components , resolve , context ) . then ( ( ) => {
185
+ resolveSrc ( globalComps , components , resolve , context , options . context ) . then ( ( ) => {
187
186
handleResult ( components )
188
187
} ) . catch ( err => {
189
188
console . error ( err )
@@ -220,13 +219,13 @@ function compileMP (content, mpOptioins) {
220
219
return content
221
220
}
222
221
223
- function resolveSrc ( originComponents , components , resolveFn , context ) {
222
+ function resolveSrc ( originComponents , components , resolveFn , context , projectRoot ) {
224
223
return Promise . all ( Object . keys ( originComponents ) . map ( k => {
225
224
return new Promise ( ( resolve , reject ) => {
226
225
resolveFn ( context , originComponents [ k ] , ( err , realSrc ) => {
227
226
if ( err ) return reject ( err )
228
227
const com = covertCCVar ( k )
229
- const { filePath, name } = getCompNameAndSrc ( context , realSrc )
228
+ const { filePath, name } = getCompNameAndSrc ( projectRoot , realSrc )
230
229
components [ com ] = { src : filePath , name }
231
230
resolve ( )
232
231
} )
0 commit comments