Skip to content

Commit

Permalink
be able to parse the recyclable flag on <template>
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanks10100 committed Nov 2, 2017
1 parent 73d34ec commit 2b3ed31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ var checkNamedExports =
'if (Object.keys(__vue_exports__).some(function (key) { return key !== "default" && key !== "__esModule" })) {' +
'console.error("named exports are not supported in *.vue files.")}\n'

function hasRecyclable (template) {
return !!(template && template.attrs && template.attrs.recyclable)
}

module.exports = function (content) {
this.cacheable()
// var isServer = this.options.target === 'node'
Expand Down Expand Up @@ -159,6 +163,9 @@ module.exports = function (content) {
if (type === 'styles') {
loader = addCssModulesToLoader(loader, part, index)
}
if (type === 'template' && hasRecyclable(part)) {
loader += '&recyclable=true'
}
// inject rewriter before css/html loader for
// extractTextPlugin use cases
if (rewriterInjectRE.test(loader)) {
Expand Down Expand Up @@ -302,6 +309,7 @@ module.exports = function (content) {
// attach render functions to exported options
exports +=
'__vue_options__.render = __vue_template__.render\n' +
(hasRecyclable(template) ? '__vue_options__["@render"] = __vue_template__["@render"]\n' : '') +
'__vue_options__.staticRenderFns = __vue_template__.staticRenderFns\n'
}

Expand Down
9 changes: 6 additions & 3 deletions lib/template-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

var compiler = require('weex-template-compiler')
var transpile = require('vue-template-es2015-compiler')
// var loaderUtils = require('loader-utils')
var loaderUtils = require('loader-utils')
var beautify = require('js-beautify').js_beautify
// var normalize = require('./normalize')
// var hotReloadAPIPath = normalize.dep('vue-hot-reload-api')
Expand Down Expand Up @@ -54,7 +54,7 @@ var beautify = require('js-beautify').js_beautify
module.exports = function (html) {
this.cacheable()
var isProduction = this.minimize || process.env.NODE_ENV === 'production'
// var query = loaderUtils.parseQuery(this.query)
var query = loaderUtils.parseQuery(this.query)
// var isServer = this.options.target === 'node'
// var isServer = false
var vueOptions = this.options.__vueOptions__
Expand All @@ -68,7 +68,9 @@ module.exports = function (html) {
// var compiled = compiler.compile(html, Object.assign({
// preserveWhitespace: vueOptions.preserveWhitespace
// }, defaultCompileOptions))
var compiled = compiler.compile(html)
var compiled = compiler.compile(html, {
recyclable: query.recyclable
})
var code
if (compiled.errors.length) {
var self = this
Expand All @@ -80,6 +82,7 @@ module.exports = function (html) {
var bubleOptions = vueOptions.buble
code = transpile('module.exports={' +
'render:' + toFunction(compiled.render) + ',' +
(compiled['@render'] ? ('"@render":' + toFunction(compiled['@render']) + ',') : '') +
'staticRenderFns: [' + compiled.staticRenderFns.map(toFunction).join(',') + ']' +
'}', bubleOptions)
// mark with stripped (this enables Vue to use correct runtime proxy detection)
Expand Down

0 comments on commit 2b3ed31

Please sign in to comment.