@@ -5,8 +5,10 @@ const qs = require('querystring')
55const plugin = require ( './plugin' )
66const selectBlock = require ( './select' )
77const loaderUtils = require ( 'loader-utils' )
8+ const { attrsToQuery } = require ( './utils' )
9+ const genStylesCode = require ( './styles' )
810const { genHotReloadCode } = require ( './hotReload' )
9- const genStyleInjectionCode = require ( './styleInjection ' )
11+ const genCustomBlocksCode = require ( './customBlocks ' )
1012const componentNormalizerPath = require . resolve ( './runtime/componentNormalizer' )
1113
1214module . exports = function ( source ) {
@@ -59,9 +61,7 @@ module.exports = function (source) {
5961
6062 // feature information
6163 const hasScoped = descriptor . styles . some ( s => s . scoped )
62- const templateAttrs = ( descriptor . template && descriptor . template . attrs ) || { }
63- const hasFunctional = templateAttrs . functional
64- const hasComment = templateAttrs . comments
64+ const hasFunctional = descriptor . template && descriptor . template . attrs . functional
6565 const needsHotReload = (
6666 ! isServer &&
6767 ! isProduction &&
@@ -73,12 +73,10 @@ module.exports = function (source) {
7373 let templateImport = `var render, staticRenderFns`
7474 if ( descriptor . template ) {
7575 const src = descriptor . template . src || resourcePath
76- const langQuery = getLangQuery ( descriptor . template )
7776 const idQuery = `&id=${ id } `
78- const scopedQuery = hasScoped ? `&scoped` : ``
79- const fnQuery = hasFunctional ? `&functional` : ``
80- const commentQuery = hasComment ? `&comment` : ``
81- const query = `?vue&type=template${ scopedQuery } ${ idQuery } ${ langQuery } ${ fnQuery } ${ commentQuery } `
77+ const scopedQuery = hasScoped ? `&scoped=true` : ``
78+ const attrsQuery = attrsToQuery ( descriptor . template . attrs )
79+ const query = `?vue&type=template${ idQuery } ${ scopedQuery } ${ attrsQuery } `
8280 const request = stringifyRequest ( src + query )
8381 templateImport = `import { render, staticRenderFns } from ${ request } `
8482 }
@@ -87,8 +85,8 @@ module.exports = function (source) {
8785 let scriptImport = `var script = {}`
8886 if ( descriptor . script ) {
8987 const src = descriptor . script . src || resourcePath
90- const langQuery = getLangQuery ( descriptor . script , 'js' )
91- const query = `?vue&type=script${ langQuery } `
88+ const attrsQuery = attrsToQuery ( descriptor . script . attrs , 'js' )
89+ const query = `?vue&type=script${ attrsQuery } `
9290 const request = stringifyRequest ( src + query )
9391 scriptImport = (
9492 `import script from ${ request } \n` +
@@ -97,15 +95,14 @@ module.exports = function (source) {
9795 }
9896
9997 // styles
100- let styleInjectionCode = ``
98+ let stylesCode = ``
10199 if ( descriptor . styles . length ) {
102- styleInjectionCode = genStyleInjectionCode (
100+ stylesCode = genStylesCode (
103101 loaderContext ,
104102 descriptor . styles ,
105103 id ,
106104 resourcePath ,
107105 stringifyRequest ,
108- getLangQuery ,
109106 needsHotReload ,
110107 isServer || isShadow // needs explicit injection?
111108 )
@@ -114,22 +111,22 @@ module.exports = function (source) {
114111 let code = `
115112${ templateImport }
116113${ scriptImport }
117- ${ styleInjectionCode }
114+ ${ stylesCode }
118115import normalizer from ${ stringifyRequest ( `!${ componentNormalizerPath } ` ) }
119116var component = normalizer(
120117 script,
121118 render,
122119 staticRenderFns,
123120 ${ hasFunctional ? `true` : `false` } ,
124- ${ / i n j e c t S t y l e s / . test ( styleInjectionCode ) ? `injectStyles` : `null` } ,
121+ ${ / i n j e c t S t y l e s / . test ( stylesCode ) ? `injectStyles` : `null` } ,
125122 ${ hasScoped ? JSON . stringify ( id ) : `null` } ,
126123 ${ isServer ? JSON . stringify ( hash ( request ) ) : `null` }
127124 ${ isShadow ? `,true` : `` }
128125)
129126 ` . trim ( )
130127
131128 if ( descriptor . customBlocks && descriptor . customBlocks . length ) {
132- // TODO custom blocks
129+ code += genCustomBlocksCode ( descriptor . customBlocks )
133130 }
134131
135132 // Expose filename. This is used by the devtools and vue runtime warnings.
@@ -146,9 +143,4 @@ var component = normalizer(
146143 return code
147144}
148145
149- function getLangQuery ( block , fallback ) {
150- const lang = block . lang || fallback
151- return lang ? `&lang=${ lang } ` : ``
152- }
153-
154146module . exports . VueLoaderPlugin = plugin
0 commit comments