Skip to content
This repository was archived by the owner on Aug 16, 2022. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5726a24

Browse files
authoredMay 6, 2018
feat: Skip style injection when style soure is empty (#65)
1 parent 0068c0f commit 5726a24

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed
 

‎src/assembler.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ export function assembleFromSource(
6565
template = template || { source: '' }
6666

6767
const hasScopedStyle = styles.some(style => style.scoped === true)
68-
const hasStyle = styles.length > 0
68+
const hasStyle = styles.some(style => Boolean(style.source))
6969
const e = (any: any): string => JSON.stringify(any)
70-
const createImport = (name: string, value: string) => value.startsWith('~')
71-
? `import ${name} from '${value.substr(1)}'`
72-
: `const ${name} = ${value}`
70+
const createImport = (name: string, value: string) =>
71+
value.startsWith('~')
72+
? `import ${name} from '${value.substr(1)}'`
73+
: `const ${name} = ${value}`
7374
const o = e
7475
const IDENTIFIER = /^[a-z0-9]+$/i
7576

@@ -293,21 +294,35 @@ const __vue_template__ = typeof __vue_render__ !== 'undefined'
293294
/* style */
294295
const __vue_inject_styles__ = ${hasStyle} ? function (inject) {
295296
if (!inject) return
296-
${styles.map(
297-
(style, index) => {
298-
const source = IDENTIFIER.test(style.source) ? style.source : e(style.source)
299-
const map = !compiler.template.isProduction
300-
? (typeof style.map === 'string' && IDENTIFIER.test(style.map) ? style.map : o(style.map))
301-
: undefined
302-
const tokens = typeof style.module === 'string' && IDENTIFIER.test(style.module) ? style.module : o(style.module)
303-
304-
return `inject("${scopeId + '_' + index}", { source: ${source}, map: ${map}, media: ${e(style.media)} })` +
305-
'\n' +
297+
${styles.map((style, index) => {
298+
const source = IDENTIFIER.test(style.source)
299+
? style.source
300+
: e(style.source)
301+
const map = !compiler.template.isProduction
302+
? typeof style.map === 'string' && IDENTIFIER.test(style.map)
303+
? style.map
304+
: o(style.map)
305+
: undefined
306+
const tokens =
307+
typeof style.module === 'string' && IDENTIFIER.test(style.module)
308+
? style.module
309+
: o(style.module)
310+
311+
return (
312+
(source
313+
? `inject("${scopeId +
314+
'_' +
315+
index}", { source: ${source}, map: ${map}, media: ${e(
316+
style.media
317+
)} })\n`
318+
: '') +
306319
(style.moduleName
307-
? `Object.defineProperty(this, "${style.moduleName}", { value: ${tokens} })` + '\n'
320+
? `Object.defineProperty(this, "${
321+
style.moduleName
322+
}", { value: ${tokens} })` + '\n'
308323
: '')
309-
}
310-
)}
324+
)
325+
})}
311326
} : undefined
312327
/* scoped */
313328
const __vue_scope_id__ = ${e(hasScopedStyle)} ? "${scopeId}" : undefined

0 commit comments

Comments
 (0)
This repository has been archived.