Home / Function/ scopedPlugin() — vue Function Reference

scopedPlugin() — vue Function Reference

Architecture documentation for the scopedPlugin() function in scoped.ts from the vue codebase.

Entity Profile

Dependency Diagram

graph TD
  9b80dd4e_5f86_2ec5_5328_da21015fcc04["scopedPlugin()"]
  8a7120c7_ffca_260b_06e7_d97501f34abf["doCompileStyle()"]
  8a7120c7_ffca_260b_06e7_d97501f34abf -->|calls| 9b80dd4e_5f86_2ec5_5328_da21015fcc04
  ecdc8b4c_fb4e_97c7_61e1_b321f397de4b["processRule()"]
  9b80dd4e_5f86_2ec5_5328_da21015fcc04 -->|calls| ecdc8b4c_fb4e_97c7_61e1_b321f397de4b
  style 9b80dd4e_5f86_2ec5_5328_da21015fcc04 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/compiler-sfc/src/stylePlugins/scoped.ts lines 7–59

const scopedPlugin: PluginCreator<string> = (id = '') => {
  const keyframes = Object.create(null)
  const shortId = id.replace(/^data-v-/, '')

  return {
    postcssPlugin: 'vue-sfc-scoped',
    Rule(rule) {
      processRule(id, rule)
    },
    AtRule(node) {
      if (
        /-?keyframes$/.test(node.name) &&
        !node.params.endsWith(`-${shortId}`)
      ) {
        // register keyframes
        keyframes[node.params] = node.params = node.params + '-' + shortId
      }
    },
    OnceExit(root) {
      if (Object.keys(keyframes).length) {
        // If keyframes are found in this <style>, find and rewrite animation names
        // in declarations.
        // Caveat: this only works for keyframes and animation rules in the same
        // <style> element.
        // individual animation-name declaration
        root.walkDecls(decl => {
          if (animationNameRE.test(decl.prop)) {
            decl.value = decl.value
              .split(',')
              .map(v => keyframes[v.trim()] || v.trim())
              .join(',')
          }
          // shorthand
          if (animationRE.test(decl.prop)) {
            decl.value = decl.value
              .split(',')
              .map(v => {
                const vals = v.trim().split(/\s+/)
                const i = vals.findIndex(val => keyframes[val])
                if (i !== -1) {
                  vals.splice(i, 1, keyframes[vals[i]])
                  return vals.join(' ')
                } else {
                  return v
                }
              })
              .join(',')
          }
        })
      }
    }
  }
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does scopedPlugin() do?
scopedPlugin() is a function in the vue codebase.
What does scopedPlugin() call?
scopedPlugin() calls 1 function(s): processRule.
What calls scopedPlugin()?
scopedPlugin() is called by 1 function(s): doCompileStyle.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free