Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vue-loader
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pi-plusplus
fork-from-github
vue-loader
Commits
542aacca
Commit
542aacca
authored
Mar 20, 2018
by
Evan You
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: ssr + scoped CSS
parent
5d0c4f7b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
2 deletions
+72
-2
index.js
lib/index.js
+2
-1
styleInjection.js
lib/styleInjection.js
+2
-0
index.js
lib/template-loader/index.js
+1
-1
scoped-css.vue
test/fixtures/scoped-css.vue
+8
-0
ssr-scoped-style.js
test/fixtures/ssr-scoped-style.js
+6
-0
ssr.spec.js
test/ssr.spec.js
+53
-0
No files found.
lib/index.js
View file @
542aacca
...
@@ -75,9 +75,10 @@ module.exports = function (source) {
...
@@ -75,9 +75,10 @@ module.exports = function (source) {
const
src
=
descriptor
.
template
.
src
||
resourcePath
const
src
=
descriptor
.
template
.
src
||
resourcePath
const
langQuery
=
getLangQuery
(
descriptor
.
template
)
const
langQuery
=
getLangQuery
(
descriptor
.
template
)
const
idQuery
=
`&id=
${
id
}
`
const
idQuery
=
`&id=
${
id
}
`
const
scopedQuery
=
hasScoped
?
`&scoped`
:
``
const
fnQuery
=
hasFunctional
?
`&functional`
:
``
const
fnQuery
=
hasFunctional
?
`&functional`
:
``
const
commentQuery
=
hasComment
?
`&comment`
:
``
const
commentQuery
=
hasComment
?
`&comment`
:
``
const
query
=
`?vue&type=template
${
idQuery
}${
langQuery
}${
fnQuery
}${
commentQuery
}
`
const
query
=
`?vue&type=template
${
scopedQuery
}${
idQuery
}${
langQuery
}${
fnQuery
}${
commentQuery
}
`
const
request
=
stringifyRequest
(
src
+
query
)
const
request
=
stringifyRequest
(
src
+
query
)
templateImport
=
`import { render, staticRenderFns } from
${
request
}
`
templateImport
=
`import { render, staticRenderFns } from
${
request
}
`
}
}
...
...
lib/styleInjection.js
View file @
542aacca
...
@@ -20,6 +20,8 @@ module.exports = function genStyleInjectionCode (
...
@@ -20,6 +20,8 @@ module.exports = function genStyleInjectionCode (
function
genStyleRequest
(
style
,
i
)
{
function
genStyleRequest
(
style
,
i
)
{
const
src
=
style
.
src
||
resourcePath
const
src
=
style
.
src
||
resourcePath
const
langQuery
=
getLangQuery
(
style
,
'css'
)
const
langQuery
=
getLangQuery
(
style
,
'css'
)
// make sure to only pass id when necessary so that we don't inject
// duplicate tags when multiple components import the same css file
const
scopedQuery
=
style
.
scoped
?
`&scoped&id=
${
id
}
`
:
``
const
scopedQuery
=
style
.
scoped
?
`&scoped&id=
${
id
}
`
:
``
const
query
=
`?vue&type=style&index=
${
i
}${
langQuery
}${
scopedQuery
}
`
const
query
=
`?vue&type=style&index=
${
i
}${
langQuery
}${
scopedQuery
}
`
return
stringifyRequest
(
src
+
query
)
return
stringifyRequest
(
src
+
query
)
...
...
lib/template-loader/index.js
View file @
542aacca
...
@@ -80,10 +80,10 @@ function actuallyCompile (sourceTemplate, options, loaderContext, query) {
...
@@ -80,10 +80,10 @@ function actuallyCompile (sourceTemplate, options, loaderContext, query) {
}
=
options
.
compilerOptions
||
{}
}
=
options
.
compilerOptions
||
{}
const
compilerOptions
=
{
const
compilerOptions
=
{
scopeId
:
query
.
scoped
!=
null
?
`data-v-
${
id
}
`
:
null
,
preserveWhitespace
,
preserveWhitespace
,
modules
:
defaultModules
.
concat
(
modules
||
[]),
modules
:
defaultModules
.
concat
(
modules
||
[]),
directives
:
directives
||
{},
directives
:
directives
||
{},
scopeId
:
id
,
comments
:
hasComment
comments
:
hasComment
}
}
...
...
test/fixtures/scoped-css.vue
View file @
542aacca
...
@@ -55,3 +55,11 @@ h1 {
...
@@ -55,3 +55,11 @@ h1 {
<svg><
template
><p></p></
template
></svg>
<svg><
template
><p></p></
template
></svg>
</div>
</div>
</template>
</template>
<
script
>
export
default
{
data
()
{
return
{
ok
:
true
}
}
}
</
script
>
test/fixtures/ssr-scoped-style.js
0 → 100644
View file @
542aacca
import
Vue
from
'vue'
import
App
from
'./scoped-css.vue'
export
default
()
=>
new
Vue
({
render
:
h
=>
h
(
App
)
})
test/ssr.spec.js
View file @
542aacca
const
SSR
=
require
(
'vue-server-renderer'
)
const
SSR
=
require
(
'vue-server-renderer'
)
const
{
const
{
genId
,
bundle
bundle
}
=
require
(
'./utils'
)
}
=
require
(
'./utils'
)
...
@@ -43,6 +44,58 @@ test('SSR style and moduleId extraction', done => {
...
@@ -43,6 +44,58 @@ test('SSR style and moduleId extraction', done => {
})
})
})
})
test
(
'SSR with scoped CSS'
,
done
=>
{
bundle
({
target
:
'node'
,
entry
:
'./test/fixtures/ssr-scoped-style.js'
,
output
:
{
path
:
'/'
,
filename
:
'test.build.js'
,
libraryTarget
:
'commonjs2'
},
externals
:
[
'vue'
]
},
code
=>
{
const
renderer
=
SSR
.
createBundleRenderer
(
code
,
{
basedir
:
__dirname
,
runInNewContext
:
'once'
})
const
context
=
{
_registeredComponents
:
new
Set
()
}
renderer
.
renderToString
(
context
,
(
err
,
res
)
=>
{
if
(
err
)
return
done
(
err
)
const
id
=
`data-v-
${
genId
(
'scoped-css.vue'
)}
`
expect
(
res
).
toContain
(
'data-server-rendered'
)
expect
(
res
).
toContain
(
`<div
${
id
}
>`
)
expect
(
res
).
toContain
(
`<svg
${
id
}
>`
)
const
style
=
context
.
styles
expect
(
style
).
toContain
(
`.test[
${
id
}
] {\n color: yellow;\n}`
)
expect
(
style
).
toContain
(
`.test[
${
id
}
]:after {\n content: \'bye!\';\n}`
)
expect
(
style
).
toContain
(
`h1[
${
id
}
] {\n color: green;\n}`
)
// scoped keyframes
expect
(
style
).
toContain
(
`.anim[
${
id
}
] {\n animation: color-
${
id
}
5s infinite, other 5s;`
)
expect
(
style
).
toContain
(
`.anim-2[
${
id
}
] {\n animation-name: color-
${
id
}
`
)
expect
(
style
).
toContain
(
`.anim-3[
${
id
}
] {\n animation: 5s color-
${
id
}
infinite, 5s other;`
)
expect
(
style
).
toContain
(
`@keyframes color-
${
id
}
{`
)
expect
(
style
).
toContain
(
`@-webkit-keyframes color-
${
id
}
{`
)
expect
(
style
).
toContain
(
`.anim-multiple[
${
id
}
] {\n animation: color-
${
id
}
5s infinite,opacity-
${
id
}
2s;`
)
expect
(
style
).
toContain
(
`.anim-multiple-2[
${
id
}
] {\n animation-name: color-
${
id
}
,opacity-
${
id
}
;`
)
expect
(
style
).
toContain
(
`@keyframes opacity-
${
id
}
{`
)
expect
(
style
).
toContain
(
`@-webkit-keyframes opacity-
${
id
}
{`
)
// >>> combinator
expect
(
style
).
toContain
(
`.foo p[
${
id
}
] .bar {\n color: red;\n}`
)
done
()
})
})
})
// TODO
// TODO
// test('css-modules in SSR', done => {
// test('css-modules in SSR', done => {
// bundle({
// bundle({
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment