Skip to content

Commit c26e76f

Browse files
committedJun 15, 2018
feat: support functional component template
1 parent 5a8771a commit c26e76f

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed
 

‎lib/modules/template-compiler.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ module.exports = function compile (template, options = {}) {
1212
source: template,
1313
filename: options.filename,
1414
compiler,
15-
transformAssetUrls: options.transformAssetUrls
15+
transformAssetUrls: options.transformAssetUrls,
16+
isFunctional: options.functional,
17+
isProduction: options.isProduction,
18+
optimizeSSR: options.optimizeSSR
1619
})
1720

1821
if (compiled.errors.length > 0) {

‎lib/template-loader.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ module.exports = function (content) {
1313
const isServer = this.target === 'node'
1414
const id = genId(this.resourcePath, process.cwd())
1515

16+
const isProduction = process.env.NODE_ENV === 'production'
17+
1618
// Acquire the query of target file
1719
const { style: stylePath } = loaderUtils.parseQuery('?' + this.request.split('?').pop())
1820
const options = Object.assign(loaderUtils.getOptions(this) || {}, {
21+
isProduction,
1922
sourceMap: this.sourceMap,
2023
fileName: this.resourcePath
2124
})
@@ -27,8 +30,7 @@ module.exports = function (content) {
2730
this.emitError('template syntax error ' + error)
2831
})
2932

30-
const shouldHotReload = isHmrEnabled && !isServer && !this.minimize &&
31-
process.env.NODE_ENV !== 'production'
33+
const shouldHotReload = isHmrEnabled && !isServer && !this.minimize && !isProduction
3234

3335
const builder = new Builder()
3436

@@ -73,6 +75,13 @@ module.exports = function (content) {
7375
`)
7476
}
7577

78+
// Functional component
79+
if (options.functional) {
80+
builder.addLine(`
81+
options.functional = true
82+
`)
83+
}
84+
7685
// Inject a snippet for adding CSS Modules object in computed
7786
if (stylePath) {
7887
builder.addLine(`

‎test/template-loader.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,9 @@ describe('vue-template-loader', () => {
142142
expect(originalPos.line).toBe(1)
143143
expect(originalPos.column).toBe(0)
144144
})
145+
146+
it('sets functional', () => {
147+
const { code } = loadCode('<div>{{ props.data }}</div>', { query: { functional: true }})
148+
expect(code).toMatch('options.functional = true')
149+
})
145150
})

0 commit comments

Comments
 (0)
Please sign in to comment.