stylePostLoader.js 790 B

12345678910111213141516171819202122232425
  1. const qs = require('querystring')
  2. const { resolveCompiler } = require('../compiler')
  3. // This is a post loader that handles scoped CSS transforms.
  4. // Injected right before css-loader by the global pitcher (../pitch.js)
  5. // for any <style scoped> selection requests initiated from within vue files.
  6. module.exports = function (source, inMap) {
  7. const query = qs.parse(this.resourceQuery.slice(1))
  8. const { compiler } = resolveCompiler(this.rootContext, this)
  9. const { code, map, errors } = compiler.compileStyle({
  10. source,
  11. filename: this.resourcePath,
  12. id: `data-v-${query.id}`,
  13. map: inMap,
  14. scoped: !!query.scoped,
  15. isProd: query.prod != null,
  16. trim: true
  17. })
  18. if (errors.length) {
  19. this.callback(errors[0])
  20. } else {
  21. this.callback(null, code, map)
  22. }
  23. }