-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
template-new.js
66 lines (57 loc) · 1.91 KB
/
template-new.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const path = require('path')
const loaderUtils = require('loader-utils')
const {
removeExt,
getPlatformExts,
getShadowTemplate
} = require('@dcloudio/uni-cli-shared')
const {
getJsonFile,
getWXComponents,
updateSpecialMethods,
getGlobalUsingComponents,
updateGenericComponents, // resolve
updateComponentGenerics, // define
updateUsingGlobalComponents
} = require('@dcloudio/uni-cli-shared/lib/cache')
const {
getPlatformFilterTag
} = require('@dcloudio/uni-cli-shared/lib/platform')
const {
normalizeNodeModules
} = require('./shared')
const templateExt = getPlatformExts().template
const filterTagName = getPlatformFilterTag() || ''
module.exports = function (content) {
this.cacheable && this.cacheable()
const vueLoaderOptions = this.loaders[0]
if (vueLoaderOptions.ident === 'vue-loader-options') {
const globalUsingComponents = getGlobalUsingComponents()
const realResourcePath = path.relative(process.env.UNI_INPUT_DIR, this.resourcePath)
const resourcePath = normalizeNodeModules(removeExt(realResourcePath) + templateExt)
const wxComponents = getWXComponents(resourcePath.replace(path.extname(resourcePath), ''))
const params = loaderUtils.parseQuery(this.resourceQuery)
/* eslint-disable no-mixed-operators */
const filterModules = JSON.parse(params && params['filter-modules'] || '{}')
Object.assign(vueLoaderOptions.options.compilerOptions, {
mp: {
platform: process.env.UNI_PLATFORM
},
filterModules,
filterTagName,
resourcePath,
emitFile: this.emitFile,
wxComponents,
getJsonFile,
getShadowTemplate,
updateSpecialMethods,
globalUsingComponents,
updateGenericComponents,
updateComponentGenerics,
updateUsingGlobalComponents
})
} else {
throw new Error('vue-loader-options parse error')
}
return content
}