|  | 
| 4 | 4 |   parseVuePartRequest, | 
| 5 | 5 |   resolveVuePart, | 
| 6 | 6 |   isVuePartRequest, | 
| 7 |  | -  transformRequireToImport | 
|  | 7 | +  transformRequireToImport, | 
|  | 8 | +  DEFAULT_LANGS | 
| 8 | 9 | } from './utils' | 
| 9 | 10 | import { | 
| 10 | 11 |   createDefaultCompiler, | 
| @@ -183,11 +184,15 @@ export default function vue(opts: Partial<VuePluginOptions> = {}): Plugin { | 
| 183 | 184 |   if (!opts.styleInjectorShadow) | 
| 184 | 185 |     opts.styleInjectorShadow = '~' + require.resolve('../runtime/shadow') | 
| 185 | 186 | 
 | 
| 186 |  | -  createVuePartRequest.defaultLang = { | 
| 187 |  | -    ...createVuePartRequest.defaultLang, | 
|  | 187 | +  const defaultLang: Record<string, string> = { | 
|  | 188 | +    ...DEFAULT_LANGS, | 
| 188 | 189 |     ...opts.defaultLang | 
| 189 | 190 |   } | 
| 190 | 191 | 
 | 
|  | 192 | +  if (opts.defaultLang && typeof opts.defaultLang.styles === 'string') { | 
|  | 193 | +    defaultLang.style = opts.defaultLang.styles | 
|  | 194 | +  } | 
|  | 195 | + | 
| 191 | 196 |   const shouldExtractCss = opts.css === false | 
| 192 | 197 |   const customBlocks: string[] = [] | 
| 193 | 198 | 
 | 
| @@ -269,10 +274,10 @@ export default function vue(opts: Partial<VuePluginOptions> = {}): Plugin { | 
| 269 | 274 | 
 | 
| 270 | 275 |     resolveId(id, importer) { | 
| 271 | 276 |       const request = id | 
| 272 |  | -       | 
| 273 |  | -      if (!importer) return  | 
|  | 277 | + | 
|  | 278 | +      if (!importer) return | 
| 274 | 279 |       if (!isVuePartRequest(id)) return | 
| 275 |  | -       | 
|  | 280 | + | 
| 276 | 281 |       id = path.resolve(path.dirname(importer), id) | 
| 277 | 282 |       const ref = parseVuePartRequest(id) | 
| 278 | 283 | 
 | 
| @@ -307,7 +312,12 @@ export default function vue(opts: Partial<VuePluginOptions> = {}): Plugin { | 
| 307 | 312 |       let map = element.map as any | 
| 308 | 313 | 
 | 
| 309 | 314 |       if (request.meta.type === 'styles') { | 
| 310 |  | -        code = prependStyle(id, request.meta.lang, code, map).code | 
|  | 315 | +        code = prependStyle( | 
|  | 316 | +          id, | 
|  | 317 | +          request.meta.lang || defaultLang.style, | 
|  | 318 | +          code, | 
|  | 319 | +          map | 
|  | 320 | +        ).code | 
| 311 | 321 |       } | 
| 312 | 322 | 
 | 
| 313 | 323 |       dL(`id: ${id}\ncode: \n${code}\nmap: ${JSON.stringify(map, null, 2)}\n\n`) | 
| @@ -344,7 +354,7 @@ export default function vue(opts: Partial<VuePluginOptions> = {}): Plugin { | 
| 344 | 354 |             if (style.content) { | 
| 345 | 355 |               style.content = prependStyle( | 
| 346 | 356 |                 filename, | 
| 347 |  | -                style.lang || 'css', | 
|  | 357 | +                style.lang || defaultLang.style, | 
| 348 | 358 |                 style.content, | 
| 349 | 359 |                 style.map | 
| 350 | 360 |               ).code | 
| @@ -388,12 +398,12 @@ export default function vue(opts: Partial<VuePluginOptions> = {}): Plugin { | 
| 388 | 398 |               code: ` | 
| 389 | 399 |             export * from '${createVuePartRequest( | 
| 390 | 400 |               filename, | 
| 391 |  | -              descriptor.script.lang || 'js', | 
|  | 401 | +              descriptor.script.lang || defaultLang.script, | 
| 392 | 402 |               'script' | 
| 393 | 403 |             )}' | 
| 394 | 404 |             import script from '${createVuePartRequest( | 
| 395 | 405 |               filename, | 
| 396 |  | -              descriptor.script.lang || 'js', | 
|  | 406 | +              descriptor.script.lang || defaultLang.script, | 
| 397 | 407 |               'script' | 
| 398 | 408 |             )}' | 
| 399 | 409 |             export default script | 
| @@ -433,22 +443,23 @@ export default function vue(opts: Partial<VuePluginOptions> = {}): Plugin { | 
| 433 | 443 |             .filter(Boolean) | 
| 434 | 444 |         } | 
| 435 | 445 | 
 | 
|  | 446 | +        // Why? | 
| 436 | 447 |         input.script.code = input.script.code.replace(/^\s+/gm, '') | 
| 437 | 448 | 
 | 
| 438 | 449 |         const result = assemble(compiler, filename, beforeAssemble(input), opts) | 
| 439 | 450 | 
 | 
| 440 | 451 |         descriptor.customBlocks.forEach((block, index) => { | 
| 441 | 452 |           if (!isAllowed(block.type)) return | 
|  | 453 | +          const lang = | 
|  | 454 | +            typeof block.attrs.lang === 'string' | 
|  | 455 | +              ? block.attrs.lang | 
|  | 456 | +              : defaultLang[block.type] || block.type | 
|  | 457 | +          const id = createVuePartRequest(filename, lang, block.type, index) | 
| 442 | 458 |           result.code += | 
| 443 | 459 |             '\n' + | 
| 444 |  | -            `export * from '${createVuePartRequest( | 
| 445 |  | -              filename, | 
| 446 |  | -              (typeof block.attrs.lang === 'string' && block.attrs.lang) || | 
| 447 |  | -                createVuePartRequest.defaultLang[block.type] || | 
| 448 |  | -                block.type, | 
| 449 |  | -              'customBlocks', | 
| 450 |  | -              index | 
| 451 |  | -            )}'` | 
|  | 460 | +            `export * from '${id}'\n` + | 
|  | 461 | +            `import __custom_block_${index}__ from '${id}'\n` + | 
|  | 462 | +            `__custom_block_${index}__(__vue_component__)` | 
| 452 | 463 |         }) | 
| 453 | 464 | 
 | 
| 454 | 465 |         dT( | 
|  | 
0 commit comments