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

wip(app): vue-loader

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