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
  10a8720e_d85f_e74e_ebd7_52d351d7789b["scopedPlugin()"]
  293256a5_d9c5_362a_dbb7_f610cfee392e["scoped.ts"]
  10a8720e_d85f_e74e_ebd7_52d351d7789b -->|defined in| 293256a5_d9c5_362a_dbb7_f610cfee392e
  e630ee87_e220_092a_592c_f7079f566b16["doCompileStyle()"]
  e630ee87_e220_092a_592c_f7079f566b16 -->|calls| 10a8720e_d85f_e74e_ebd7_52d351d7789b
  1f0a1b49_024c_6fba_e857_32ad923156cd["processRule()"]
  10a8720e_d85f_e74e_ebd7_52d351d7789b -->|calls| 1f0a1b49_024c_6fba_e857_32ad923156cd
  style 10a8720e_d85f_e74e_ebd7_52d351d7789b 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, defined in packages/compiler-sfc/src/stylePlugins/scoped.ts.
Where is scopedPlugin() defined?
scopedPlugin() is defined in packages/compiler-sfc/src/stylePlugins/scoped.ts at line 7.
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