Skip to content

Commit f35f233

Browse files
committed
test: ssr + css modules
1 parent 542aacc commit f35f233

File tree

2 files changed

+51
-25
lines changed

2 files changed

+51
-25
lines changed

Diff for: lib/styleInjection.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = function genStyleInjectionCode (
4242
const name = JSON.stringify(moduleName)
4343

4444
if (!needsHotReload) {
45-
styleInjectionCode += `this[${name}] = ${locals}`
45+
styleInjectionCode += `this[${name}] = ${locals}\n`
4646
} else {
4747
styleInjectionCode += `
4848
cssModules[${name}] = ${locals}

Diff for: test/ssr.spec.js

+50-24
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ const SSR = require('vue-server-renderer')
22

33
const {
44
genId,
5-
bundle
5+
bundle,
6+
baseConfig,
7+
interopDefault
68
} = require('./utils')
79

810
test('SSR style and moduleId extraction', done => {
@@ -96,29 +98,53 @@ test('SSR with scoped CSS', done => {
9698
})
9799
})
98100

99-
// TODO
100-
// test('css-modules in SSR', done => {
101-
// bundle({
102-
// entry: 'css-modules.vue',
103-
// target: 'node',
104-
// output: Object.assign({}, globalConfig.output, {
105-
// libraryTarget: 'commonjs2'
106-
// })
107-
// }, (code, warnings) => {
108-
// // http://stackoverflow.com/questions/17581830/load-node-js-module-from-string-in-memory
109-
// function requireFromString (src, filename) {
110-
// const Module = module.constructor
111-
// const m = new Module()
112-
// m._compile(src, filename)
113-
// return m.exports
114-
// }
101+
test('SSR + CSS Modules', done => {
102+
const baseLoaders = [
103+
'vue-style-loader',
104+
{
105+
loader: 'css-loader',
106+
options: { modules: true }
107+
}
108+
]
109+
110+
bundle({
111+
entry: 'css-modules.vue',
112+
target: 'node',
113+
output: Object.assign({}, baseConfig.output, {
114+
libraryTarget: 'commonjs2'
115+
}),
116+
modify: config => {
117+
config.module.rules = [
118+
{ test: /\.vue$/, loader: 'vue-loader' },
119+
{
120+
test: /\.css$/,
121+
use: baseLoaders
122+
},
123+
{
124+
test: /\.stylus$/,
125+
use: [
126+
...baseLoaders,
127+
'stylus-loader'
128+
]
129+
}
130+
]
131+
}
132+
}, code => {
133+
// http://stackoverflow.com/questions/17581830/load-node-js-module-from-string-in-memory
134+
function requireFromString (src, filename) {
135+
const Module = require('module')
136+
const m = new Module()
137+
m._compile(src, filename)
138+
return m.exports
139+
}
115140

116-
// const output = interopDefault(requireFromString(code, './test.build.js'))
117-
// const mockInstance = {}
141+
const output = interopDefault(requireFromString(code, './test.build.js'))
142+
const mockInstance = {}
118143

119-
// output.beforeCreate.forEach(hook => hook.call(mockInstance))
120-
// expect(mockInstance.style.red).toBeDefined()
144+
output.beforeCreate.forEach(hook => hook.call(mockInstance))
145+
expect(mockInstance.style.red).toBeDefined()
146+
expect(mockInstance.$style.red).toBeDefined()
121147

122-
// done()
123-
// })
124-
// })
148+
done()
149+
})
150+
})

0 commit comments

Comments
 (0)