提交 cc34062c 编写于 作者: fxy060608's avatar fxy060608

wip(app): vue-loader

上级 27387af1
......@@ -7,6 +7,7 @@ exports.vueLoader = {
{
loader: 'vue-loader',
options: {
hotReload: false,
compiler: require('../../../../../lib/weex-template-compiler'),
},
},
......
......@@ -85,13 +85,21 @@ module.exports = function genStyleInjectionCode (
if (style.module) genCSSModulesCode(style, request, i)
}
})
} else {
} else {// fixed by xxxxxx nvue style
styleInjectionCode = `if(!this.options.style){this.options.style = {}}
if(Vue.prototype.__merge_style && Vue.prototype.__$appStyle__){Vue.prototype.__merge_style(Vue.prototype.__$appStyle__, this.options.style)}
`
styles.forEach((style, i) => {
if (isNotEmptyStyle(style)) {
const request = genStyleRequest(style, i)
styleInjectionCode += (
`var style${i} = require(${request})\n` +
`if (style${i}.__inject__) style${i}.__inject__(context)\n`
`if(Vue.prototype.__merge_style){
Vue.prototype.__merge_style(require(${request}).default, this.options.style)
}else{
Object.assign(this.options.style,require(${request}).default)
}\n`//fixed by xxxxxx 简单处理,与 weex-vue-loader 保持一致
//`var style${i} = require(${request})\n` +
//`if (style${i}.__inject__) style${i}.__inject__(context)\n`
)
if (style.module) genCSSModulesCode(style, request, i)
}
......
......@@ -110,6 +110,9 @@ module.exports = function (source) {
// template
let templateImport = `var render, staticRenderFns`
let templateRequest
// fixed by xxxxxx (recyclable,auto components)
templateImport += `, recyclableRender, components`
const recyclable = descriptor.template && !!(template.attrs && template.attrs.recyclable)
if (descriptor.template) {
const src = descriptor.template.src || resourcePath
const idQuery = `&id=${id}`
......@@ -117,7 +120,9 @@ module.exports = function (source) {
const attrsQuery = attrsToQuery(descriptor.template.attrs)
const query = `?vue&type=template${idQuery}${scopedQuery}${attrsQuery}${inheritQuery}`
const request = templateRequest = stringifyRequest(src + query)
templateImport = `import { render, staticRenderFns } from ${request}`
// templateImport = `import { render, staticRenderFns } from ${request}`
// fixed by xxxxxx (auto components)
templateImport = `import { render, staticRenderFns, recyclableRender, components } from ${request}`
}
// script
......@@ -133,7 +138,7 @@ module.exports = function (source) {
)
}
// styles
// styles fixed by xxxxxx
let stylesCode = ``
if (descriptor.styles.length) {
stylesCode = genStylesCode(
......@@ -143,10 +148,10 @@ module.exports = function (source) {
resourcePath,
stringifyRequest,
needsHotReload,
isServer || isShadow // needs explicit injection?
true // isServer || isShadow // needs explicit injection?
)
}
// fixed by xxxxxx (injectStyles,auto components)
let code = `
${templateImport}
${scriptImport}
......@@ -159,10 +164,11 @@ var component = normalizer(
render,
staticRenderFns,
${hasFunctional ? `true` : `false`},
${/injectStyles/.test(stylesCode) ? `injectStyles` : `null`},
${`null`/* fixed by xxxxxx */},
${hasScoped ? JSON.stringify(id) : `null`},
${isServer ? JSON.stringify(hash(request)) : `null`}
${isShadow ? `,true` : ``}
${isShadow ? `,true` : ``},
components
)
`.trim() + `\n`
......@@ -174,11 +180,14 @@ var component = normalizer(
stringifyRequest
)
}
if (needsHotReload) {
code += `\n` + genHotReloadCode(id, hasFunctional, templateRequest)
}
// fixed by xxxxxx (app-nvue injectStyles)
if (/injectStyles/.test(stylesCode)) {
code +=`\ninjectStyles.call(component)`
}
// Expose filename. This is used by the devtools and Vue runtime warnings.
if (!isProduction) {
// Expose the file's full path in development, so that it can be opened
......@@ -189,7 +198,9 @@ var component = normalizer(
// For security reasons, only expose the file's basename in production.
code += `\ncomponent.options.__file = ${JSON.stringify(filename)}`
}
if (recyclable) { // fixed by xxxxxx app-plus recyclable
code += `\nrecyclableRender && (component.options["@render"] = recyclableRender)` // fixed by xxxxxx
}
code += `\nexport default component.exports`
return code
}
......
......@@ -64,21 +64,21 @@ module.exports = function (source) {
const frame = compiler.generateCodeFrame(source, start, end)
return ` ${msg}\n\n${pad(frame)}`
}).join(`\n\n`) +
'\n'
'\n at ' + finalOptions.filename + ':0' // fixed by xxxxxx
)
} else {
loaderContext.emitError(
`\n Error compiling template:\n${pad(compiled.source)}\n` +
compiled.errors.map(e => ` - ${e}`).join('\n') +
'\n'
'\n at ' + finalOptions.filename + ':0' // fixed by xxxxxx
)
}
}
const { code } = compiled
// finish with ESM exports
return code + `\nexport { render, staticRenderFns }`
// fixed by xxxxxx recyclableRender, components
// finish with ESM exports
return code + `\nexport { render, staticRenderFns, recyclableRender, components }`
}
function pad (source) {
......
......@@ -6,6 +6,7 @@ export const vueLoader: RuleSetRule = {
{
loader: 'vue-loader',
options: {
hotReload: false,
compiler: require('../../../../../lib/weex-template-compiler'),
},
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册