Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
feat: custom block
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin committed Jan 12, 2021
1 parent fe7393c commit 19f7274
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
4 changes: 1 addition & 3 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,5 @@ The options for jsx transform.

## Todo

- Custom Block
- SSR Build
- Sourcemap
- error handle
- Sourcemap
22 changes: 20 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ function injectStyles (context) {
}
}\n`

// TODO custom block
// // Expose filename. This is used by the devtools and Vue runtime warnings.
// custom block
code += genCustomBlockCode(filePath, descriptor)
// Expose filename. This is used by the devtools and Vue runtime warnings.
if (options.isProduction) {
// Expose the file's full path in development, so that it can be opened
// from the devtools.
Expand Down Expand Up @@ -161,6 +162,23 @@ function genTemplateRequest(filename: string, descriptor: SFCDescriptor) {
}
}

function genCustomBlockCode(filename: string, descriptor: SFCDescriptor) {
let code = ''
descriptor.customBlocks.forEach((block, index) => {
// if (block.src) {
// linkSrcToDescriptor(block.src, descriptor)
// }
const src = filename
const attrsQuery = attrsToQuery(block.attrs, block.type)
// const srcQuery = block.src ? `&src` : ``
const query = `?vue&type=${block.type}&index=${index}${attrsQuery}`
const request = JSON.stringify(src + query)
code += `import block${index} from ${request}\n`
code += `if (typeof block${index} === 'function') block${index}(component)\n`
})
return code
}

function genHmrCode(id: string, functional: boolean, templateRequest?: string) {
return `\n/* hot reload */
import __VUE_HMR_RUNTIME__ from "${vueHotReload}"
Expand Down

0 comments on commit 19f7274

Please sign in to comment.