Skip to content
This repository was archived by the owner on Aug 16, 2022. It is now read-only.

Commit d413d22

Browse files
committed
feat: add css modules capability to style-compiler
1 parent 9a30f9e commit d413d22

File tree

3 files changed

+228
-8
lines changed

3 files changed

+228
-8
lines changed

package-lock.json

+218-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"lodash.defaultsdeep": "^4.6.0",
3939
"lru-cache": "^4.1.1",
4040
"postcss": "^6.0.12",
41+
"postcss-modules": "^0.8.0",
4142
"postcss-selector-parser": "^2.2.3",
4243
"source-map": "^0.6.1",
4344
"vue-hot-reload-api": "^2.1.0",

src/style-compiler/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const postcss = require('postcss')
2+
const cssModules = require('postcss-modules')
23
const defaults = require('lodash.defaultsdeep')
34

45
const trim = require('./plugins/trim')
@@ -40,9 +41,16 @@ module.exports = function compileStyle (style, filename, config) {
4041
plugins.push(scopeId({ id: config.scopeId }))
4142
}
4243

44+
let modules
45+
if (style.descriptor.module) {
46+
plugins.push(cssModules({
47+
getJSON: (_, output) => { modules = output }
48+
}))
49+
}
50+
4351
const output = postcss(plugins).process(style.code, options)
4452
const prepare = result => {
45-
const output = { code: result.css }
53+
const output = { code: result.css, modules }
4654

4755
if (config.needMap) { output.map = result.map }
4856
result.warnings().forEach(warning => config.onWarn(warning))

0 commit comments

Comments
 (0)