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
f35f233b
Commit
f35f233b
authored
Mar 20, 2018
by
Evan You
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: ssr + css modules
parent
542aacca
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
25 deletions
+51
-25
styleInjection.js
lib/styleInjection.js
+1
-1
ssr.spec.js
test/ssr.spec.js
+50
-24
No files found.
lib/styleInjection.js
View file @
f35f233b
...
...
@@ -42,7 +42,7 @@ module.exports = function genStyleInjectionCode (
const
name
=
JSON
.
stringify
(
moduleName
)
if
(
!
needsHotReload
)
{
styleInjectionCode
+=
`this[
${
name
}
] =
${
locals
}
`
styleInjectionCode
+=
`this[
${
name
}
] =
${
locals
}
\n
`
}
else
{
styleInjectionCode
+=
`
cssModules[
${
name
}
] =
${
locals
}
...
...
test/ssr.spec.js
View file @
f35f233b
...
...
@@ -2,7 +2,9 @@ const SSR = require('vue-server-renderer')
const
{
genId
,
bundle
bundle
,
baseConfig
,
interopDefault
}
=
require
(
'./utils'
)
test
(
'SSR style and moduleId extraction'
,
done
=>
{
...
...
@@ -96,29 +98,53 @@ test('SSR with scoped CSS', done => {
})
})
// TODO
// test('css-modules in SSR', done => {
// bundle({
// entry: 'css-modules.vue',
// target: 'node',
// output: Object.assign({}, globalConfig.output, {
// libraryTarget: 'commonjs2'
// })
// }, (code, warnings) => {
// // http://stackoverflow.com/questions/17581830/load-node-js-module-from-string-in-memory
// function requireFromString (src, filename) {
// const Module = module.constructor
// const m = new Module()
// m._compile(src, filename)
// return m.exports
// }
test
(
'SSR + CSS Modules'
,
done
=>
{
const
baseLoaders
=
[
'vue-style-loader'
,
{
loader
:
'css-loader'
,
options
:
{
modules
:
true
}
}
]
// const output = interopDefault(requireFromString(code, './test.build.js'))
// const mockInstance = {}
bundle
({
entry
:
'css-modules.vue'
,
target
:
'node'
,
output
:
Object
.
assign
({},
baseConfig
.
output
,
{
libraryTarget
:
'commonjs2'
}),
modify
:
config
=>
{
config
.
module
.
rules
=
[
{
test
:
/
\.
vue$/
,
loader
:
'vue-loader'
},
{
test
:
/
\.
css$/
,
use
:
baseLoaders
},
{
test
:
/
\.
stylus$/
,
use
:
[
...
baseLoaders
,
'stylus-loader'
]
}
]
}
},
code
=>
{
// http://stackoverflow.com/questions/17581830/load-node-js-module-from-string-in-memory
function
requireFromString
(
src
,
filename
)
{
const
Module
=
require
(
'module'
)
const
m
=
new
Module
()
m
.
_compile
(
src
,
filename
)
return
m
.
exports
}
const
output
=
interopDefault
(
requireFromString
(
code
,
'./test.build.js'
))
const
mockInstance
=
{}
// output.beforeCreate.forEach(hook => hook.call(mockInstance))
// expect(mockInstance.style.red).toBeDefined()
output
.
beforeCreate
.
forEach
(
hook
=>
hook
.
call
(
mockInstance
))
expect
(
mockInstance
.
style
.
red
).
toBeDefined
()
expect
(
mockInstance
.
$style
.
red
).
toBeDefined
()
//
done()
//
})
//
})
done
()
})
})
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