File tree Expand file tree Collapse file tree 4 files changed +35
-4
lines changed Expand file tree Collapse file tree 4 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -22,3 +22,7 @@ export default {
2222 color : green ;
2323}
2424 </style >
25+
26+ <docs >
27+ This component is fire. // <-- this should be logged
28+ </docs >
Original file line number Diff line number Diff line change 1+ module . exports = function ( source ) {
2+ this . callback ( null , `export default function (Comp) {
3+ Comp.mounted = () => console.log(${ JSON . stringify ( source . trim ( ) ) } )
4+ }` )
5+ }
Original file line number Diff line number Diff line change @@ -39,6 +39,11 @@ module.exports = {
3939 } ,
4040 'css-loader'
4141 ]
42+ } ,
43+ // target <docs> custom blocks
44+ {
45+ resourceQuery : / b l o c k T y p e = d o c s / ,
46+ loader : require . resolve ( './docs-loader' )
4247 }
4348 ]
4449 } ,
Original file line number Diff line number Diff line change @@ -160,10 +160,6 @@ const loader: webpack.loader.Loader = function(source) {
160160 `script.render = render`
161161 ] . join ( '\n' )
162162
163- if ( descriptor . customBlocks && descriptor . customBlocks . length ) {
164- // TODO custom blocks
165- }
166-
167163 // attach scope Id for runtime use
168164 if ( hasScoped ) {
169165 code += `\nscript.__scopeId = "data-v-${ id } "`
@@ -187,6 +183,27 @@ const loader: webpack.loader.Loader = function(source) {
187183 code += `\nscript.__file = ${ JSON . stringify ( path . basename ( resourcePath ) ) } `
188184 }
189185
186+ // custom blocks
187+ if ( descriptor . customBlocks && descriptor . customBlocks . length ) {
188+ code += `\n/* custom blocks */\n`
189+ code +=
190+ descriptor . customBlocks
191+ . map ( ( block , i ) => {
192+ const src = block . attrs . src || resourcePath
193+ const attrsQuery = attrsToQuery ( block . attrs )
194+ const blockTypeQuery = `&blockType=${ qs . escape ( block . type ) } `
195+ const issuerQuery = block . attrs . src
196+ ? `&issuerPath=${ qs . escape ( resourcePath ) } `
197+ : ''
198+ const query = `?vue&type=custom&index=${ i } ${ blockTypeQuery } ${ issuerQuery } ${ attrsQuery } ${ resourceQuery } `
199+ return (
200+ `import block${ i } from ${ stringifyRequest ( src + query ) } \n` +
201+ `if (typeof block${ i } === 'function') block${ i } (script)`
202+ )
203+ } )
204+ . join ( `\n` ) + `\n`
205+ }
206+
190207 // finalize
191208 code += `\n\nexport default script`
192209 return code
You can’t perform that action at this time.
0 commit comments