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

Commit

Permalink
feat: add css modules capability to style-compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
znck committed Oct 29, 2017
1 parent 9a30f9e commit d413d22
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 8 deletions.
225 changes: 218 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"lodash.defaultsdeep": "^4.6.0",
"lru-cache": "^4.1.1",
"postcss": "^6.0.12",
"postcss-modules": "^0.8.0",
"postcss-selector-parser": "^2.2.3",
"source-map": "^0.6.1",
"vue-hot-reload-api": "^2.1.0",
Expand Down
10 changes: 9 additions & 1 deletion src/style-compiler/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const postcss = require('postcss')
const cssModules = require('postcss-modules')
const defaults = require('lodash.defaultsdeep')

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

let modules
if (style.descriptor.module) {
plugins.push(cssModules({
getJSON: (_, output) => { modules = output }
}))
}

const output = postcss(plugins).process(style.code, options)
const prepare = result => {
const output = { code: result.css }
const output = { code: result.css, modules }

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

0 comments on commit d413d22

Please sign in to comment.