Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function (content) {
if (process.env.UNI_USING_COMPONENTS) {
return require('./template-new').call(this, content)
}
this.cacheable && this.cacheable()
const realResourcePath = path.relative(process.env.UNI_INPUT_DIR, this.resourcePath)
if (process.env.UNI_USING_COMPONENTS) {
// 向 uni-template-compier 传递 emitFile
const vueLoaderOptions = this.loaders[0]
if (vueLoaderOptions.ident === 'vue-loader-options') {
Object.assign(vueLoaderOptions.options.compilerOptions, {
resourcePath: removeExt(realResourcePath) + templateExt,
emitFile: this.emitFile
})
} else {
throw new Error('vue-loader-options parse error')
}
} else {
if (!content.trim()) {
content = ''
}
cacheTemplate(realResourcePath, content)
const query = qs.parse(this.resourceQuery.slice(1))
const {
id
Object.keys(assets).forEach(name => {
if (components.has(name.replace('.js', ''))) {
const chunkName = name.replace('.js', '-create-component')
let moduleId = ''
if (name.indexOf('node-modules') === 0) {
const modulePath = removeExt(restoreNodeModules(name))
const resource = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, '..', modulePath))
const altResource = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, modulePath))
moduleId = findComponentModuleId(modules, concatenatedModules, resource, altResource)
} else {
const resource = removeExt(path.resolve(process.env.UNI_INPUT_DIR, name))
moduleId = findComponentModuleId(modules, concatenatedModules, resource)
}
const origSource = assets[name].source()
if (origSource.length !== `Component({})`.length) { // 不是空组件
const globalVar = process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'global'
// 主要是为了解决支付宝旧版本, Component 方法只在组件 js 里有,需要挂在 my.defineComponent
let beforeCode = ''
if (process.env.UNI_PLATFORM === 'mp-alipay') {
beforeCode = ';my.defineComponent || (my.defineComponent = Component);'
}
Object.keys(assets).forEach(name => {
if (components.has(name.replace('.js', ''))) {
const chunkName = name.replace('.js', '-create-component')
let moduleId = ''
if (name.indexOf('node-modules') === 0) {
const modulePath = removeExt(restoreNodeModules(name))
const resource = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, '..', modulePath))
const altResource = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, modulePath))
moduleId = findComponentModuleId(modules, concatenatedModules, resource, altResource)
} else {
const resource = removeExt(path.resolve(process.env.UNI_INPUT_DIR, name))
moduleId = findComponentModuleId(modules, concatenatedModules, resource)
}
const origSource = assets[name].source()
if (origSource.length !== `Component({})`.length) { // 不是空组件
const globalVar = process.env.UNI_PLATFORM === 'mp-alipay' ? 'my' : 'global'
// 主要是为了解决支付宝旧版本, Component 方法只在组件 js 里有,需要挂在 my.defineComponent
let beforeCode = ''
if (process.env.UNI_PLATFORM === 'mp-alipay') {
beforeCode = ';my.defineComponent || (my.defineComponent = Component);'
}
const source = beforeCode + origSource +
`
;(${globalVar}["webpackJsonp"] = ${globalVar}["webpackJsonp"] || []).push([
'${chunkName}',
{
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,
module.exports = function(content, map) {
this.cacheable && this.cacheable()
const resourcePath = removeExt(
normalizePath(path.relative(process.env.UNI_INPUT_DIR, this.resourcePath))
)
content = content + getUsingComponentsCode(resourcePath)
// TODO 自动导入 vue 组件(h5,小程序,app[vue,nvue])
// 1. 需要 template-loader 解析出所有自定义组件()
// 2. 根据自定义组件信息生成引用代码
// 3. node-modules中的组件不提供自动导入
return content
}
module => {
let moduleResource = module.resource
if (
!moduleResource ||
(
moduleResource.indexOf('.vue') === -1 &&
moduleResource.indexOf('.nvue') === -1
)
) {
return
}
moduleResource = removeExt(module.resource)
return moduleResource === resource || moduleResource === altResource
}
)
cacheCompilerOptions (name, options = {}) {
name = removeExt(name)
compilerOptions[name] = Object.assign(compilerOptions[name] || {}, options)
},
cacheCompiledComponentTemplates (name, options) {
cacheTemplate (name, content) {
templates[removeExt(name)] = content
},
cacheCompilerOptions (name, options = {}) {