Skip to content

Commit 1c15148

Browse files
authored
Merge pull request #11 from Hanks10100/scoped
Support to generate scopeId of css classes.
2 parents 332be8d + 62182b1 commit 1c15148

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

lib/loader.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ module.exports = function (content) {
209209
}
210210

211211
var parts = parse(content, fileName, this.sourceMap)
212-
// var hasScoped = parts.styles.some(function (s) { return s.scoped })
212+
// var hasGlobal = parts.styles.some(function (s) { return !!s.global })
213+
// var scopeId = hasGlobal ? '@GLOBAL' : ('data-v-' + genId(filePath))
214+
var scopeId = 'data-v-' + genId(filePath)
213215
var output = 'var __vue_exports__, __vue_options__\n'
214216

215217
// css modules
@@ -304,9 +306,9 @@ module.exports = function (content) {
304306
}
305307

306308
// attach scoped id
307-
// if (hasScoped) {
308-
// exports += '__vue_options__._scopeId = "' + moduleId + '"\n'
309-
// }
309+
if (parts.styles.length) {
310+
exports += '__vue_options__._scopeId = "' + scopeId + '"\n'
311+
}
310312

311313
// if (Object.keys(cssModules).length) {
312314
// // inject style modules as computed properties
@@ -320,11 +322,16 @@ module.exports = function (content) {
320322

321323
exports += '__vue_options__.style = __vue_options__.style || {}\n' +
322324
'__vue_styles__.forEach(function (module) {\n' +
323-
'for (var name in module) {\n' +
324-
'__vue_options__.style[name] = module[name]\n' +
325-
'}\n' +
325+
' for (var name in module) {\n' +
326+
' __vue_options__.style[name] = module[name]\n' +
327+
' }\n' +
326328
'})\n'
327329

330+
// support to register static styles
331+
exports += 'if (typeof __register_static_styles__ === "function") {\n' +
332+
' __register_static_styles__(__vue_options__._scopeId, __vue_styles__)\n' +
333+
'}\n'
334+
328335
if (!query.inject) {
329336
output += exports
330337
// hot reload

lib/parser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// TODO: use weex-tempalte-compiler
12
var compiler = require('vue-template-compiler')
23
var cache = require('lru-cache')(100)
34
var hash = require('hash-sum')
@@ -12,6 +13,7 @@ module.exports = function (content, filename, needMap) {
1213
var filenameWithHash = filename + '?' + cacheKey
1314
var output = cache.get(cacheKey)
1415
if (output) return output
16+
// TODO: support to use "global" in <style>
1517
output = compiler.parseComponent(content, { pad: true })
1618
if (needMap) {
1719
if (output.script && !output.script.src) {

0 commit comments

Comments
 (0)