@vue/compiler-sfc
@vue/compiler-sfc
Last updated a year ago by yyx990803 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @vue/compiler-sfc 
SYNC missed versions from official npm registry.

@vue/compiler-sfc

Lower level utilities for compiling Vue Single File Components

Note: as of 3.2.13+, this package is included as a dependency of the main vue package and can be accessed as vue/compiler-sfc. This means you no longer need to explicitly install this package and ensure its version match that of vue's. Just use the main vue/compiler-sfc deep import instead.

This package contains lower level utilities that you can use if you are writing a plugin / transform for a bundler or module system that compiles Vue Single File Components (SFCs) into JavaScript. It is used in vue-loader and @vitejs/plugin-vue.

API

The API is intentionally low-level due to the various considerations when integrating Vue SFCs in a build system:

  • Separate hot-module replacement (HMR) for script, template and styles

    • template updates should not reset component state
    • style updates should be performed without component re-render
  • Leveraging the tool's plugin system for pre-processor handling. e.g. <style lang="scss"> should be processed by the corresponding webpack loader.

  • In some cases, transformers of each block in an SFC do not share the same execution context. For example, when used with thread-loader or other parallelized configurations, the template sub-loader in vue-loader may not have access to the full SFC and its descriptor.

The general idea is to generate a facade module that imports the individual blocks of the component. The trick is the module imports itself with different query strings so that the build system can handle each request as "virtual" modules:

                                  +--------------------+
                                  |                    |
                                  |  script transform  |
                           +----->+                    |
                           |      +--------------------+
                           |
+--------------------+     |      +--------------------+
|                    |     |      |                    |
|  facade transform  +----------->+ template transform |
|                    |     |      |                    |
+--------------------+     |      +--------------------+
                           |
                           |      +--------------------+
                           +----->+                    |
                                  |  style transform   |
                                  |                    |
                                  +--------------------+

Where the facade module looks like this:

// main script
import script from '/project/foo.vue?vue&type=script'
// template compiled to render function
import { render } from '/project/foo.vue?vue&type=template&id=xxxxxx'
// css
import '/project/foo.vue?vue&type=style&index=0&id=xxxxxx'

// attach render function to script
script.render = render

// attach additional metadata
// some of these should be dev only
script.__file = 'example.vue'
script.__scopeId = 'xxxxxx'

// additional tooling-specific HMR handling code
// using __VUE_HMR_API__ global

export default script

High Level Workflow

  1. In facade transform, parse the source into descriptor with the parse API and generate the above facade module code based on the descriptor;

  2. In script transform, use compileScript to process the script. This handles features like <script setup> and CSS variable injection. Alternatively, this can be done directly in the facade module (with the code inlined instead of imported), but it will require rewriting export default to a temp variable (a rewriteDefault convenience API is provided for this purpose) so additional options can be attached to the exported object.

  3. In template transform, use compileTemplate to compile the raw template into render function code.

  4. In style transform, use compileStyle to compile raw CSS to handle <style scoped>, <style module> and CSS variable injection.

Options needed for these APIs can be passed via the query string.

For detailed API references and options, check out the source type definitions. For actual usage of these APIs, check out @vitejs/plugin-vue or vue-loader.

Current Tags

  • 3.5.0-alpha.5                                ...           alpha (5 months ago)
  • 3.5.0-beta.3                                ...           beta (4 months ago)
  • 3.5.13                                ...           latest (a month ago)
  • 3.5.0-rc.1                                ...           rc (4 months ago)
  • 2.7.0-alpha.12                                ...           v2-alpha (3 years ago)
  • 2.7.16-beta.2                                ...           v2-beta (a year ago)
  • 2.7.16                                ...           v2-latest (a year ago)

277 Versions

  • 3.5.13                                ...           a month ago
  • 3.5.12                                ...           2 months ago
  • 3.5.11                                ...           3 months ago
  • 3.5.10                                ...           3 months ago
  • 3.5.9                                ...           3 months ago
  • 3.5.8                                ...           3 months ago
  • 3.5.7                                ...           3 months ago
  • 3.5.6                                ...           3 months ago
  • 3.5.5                                ...           3 months ago
  • 3.5.4                                ...           3 months ago
  • 3.5.3                                ...           4 months ago
  • 3.5.2                                ...           4 months ago
  • 3.5.1                                ...           4 months ago
  • 3.5.0                                ...           4 months ago
  • 3.5.0-rc.1                                ...           4 months ago
  • 3.5.0-beta.3                                ...           4 months ago
  • 3.4.38                                ...           4 months ago
  • 3.5.0-beta.2                                ...           4 months ago
  • 3.5.0-beta.1                                ...           5 months ago
  • 3.4.37                                ...           5 months ago
  • 3.4.36                                ...           5 months ago
  • 3.5.0-alpha.5                                ...           5 months ago
  • 3.4.35                                ...           5 months ago
  • 3.5.0-alpha.4                                ...           5 months ago
  • 3.4.34                                ...           5 months ago
  • 3.5.0-alpha.3                                ...           5 months ago
  • 3.4.33                                ...           5 months ago
  • 3.4.32                                ...           5 months ago
  • 3.4.31                                ...           6 months ago
  • 3.4.30                                ...           6 months ago
  • 3.4.29                                ...           6 months ago
  • 3.4.28                                ...           6 months ago
  • 3.4.27                                ...           8 months ago
  • 3.5.0-alpha.2                                ...           8 months ago
  • 3.4.26                                ...           8 months ago
  • 3.5.0-alpha.1                                ...           8 months ago
  • 3.4.25                                ...           8 months ago
  • 3.4.24                                ...           8 months ago
  • 3.4.23                                ...           8 months ago
  • 3.4.22                                ...           8 months ago
  • 3.4.21                                ...           10 months ago
  • 3.4.20                                ...           10 months ago
  • 3.4.19                                ...           10 months ago
  • 3.4.18                                ...           a year ago
  • 3.4.17                                ...           a year ago
  • 3.4.16                                ...           a year ago
  • 3.4.15                                ...           a year ago
  • 3.4.14                                ...           a year ago
  • 3.4.13                                ...           a year ago
  • 3.4.12                                ...           a year ago
  • 3.4.11                                ...           a year ago
  • 3.4.10                                ...           a year ago
  • 3.4.9                                ...           a year ago
  • 3.4.8                                ...           a year ago
  • 3.4.7                                ...           a year ago
  • 3.4.6                                ...           a year ago
  • 3.4.5                                ...           a year ago
  • 3.4.4                                ...           a year ago
  • 3.4.3                                ...           a year ago
  • 3.4.2                                ...           a year ago
  • 3.4.1                                ...           a year ago
  • 3.4.0                                ...           a year ago
  • 3.4.0-rc.3                                ...           a year ago
  • 3.4.0-rc.2                                ...           a year ago
  • 3.4.0-rc.1                                ...           a year ago
  • 2.7.16                                ...           a year ago
  • 3.4.0-beta.4                                ...           a year ago
  • 3.3.13                                ...           a year ago
  • 3.4.0-beta.3                                ...           a year ago
  • 3.3.12                                ...           a year ago
  • 3.4.0-beta.2                                ...           a year ago
  • 2.7.16-beta.2                                ...           a year ago
  • 3.4.0-beta.1                                ...           a year ago
  • 3.3.11                                ...           a year ago
  • 2.7.16-beta.1                                ...           a year ago
  • 3.4.0-alpha.4                                ...           a year ago
  • 3.3.10                                ...           a year ago
  • 3.4.0-alpha.3                                ...           a year ago
  • 3.4.0-alpha.2                                ...           a year ago
  • 3.3.9                                ...           a year ago
  • 3.3.8                                ...           a year ago
  • 3.4.0-alpha.1                                ...           a year ago
  • 3.3.7                                ...           a year ago
  • 2.7.15                                ...           a year ago
  • 3.3.6                                ...           a year ago
  • 3.3.5                                ...           a year ago
  • 3.3.4                                ...           2 years ago
  • 3.3.3                                ...           2 years ago
  • 3.3.2                                ...           2 years ago
  • 3.3.1                                ...           2 years ago
  • 3.3.0                                ...           2 years ago
  • 3.3.0-beta.5                                ...           2 years ago
  • 3.3.0-beta.4                                ...           2 years ago
  • 3.3.0-beta.3                                ...           2 years ago
  • 3.3.0-beta.2                                ...           2 years ago
  • 3.3.0-beta.1                                ...           2 years ago
  • 3.3.0-alpha.13                                ...           2 years ago
  • 3.3.0-alpha.12                                ...           2 years ago
  • 3.3.0-alpha.11                                ...           2 years ago
  • 3.3.0-alpha.10                                ...           2 years ago
  • 3.3.0-alpha.9                                ...           2 years ago
  • 3.3.0-alpha.8                                ...           2 years ago
  • 3.3.0-alpha.7                                ...           2 years ago
  • 3.3.0-alpha.6                                ...           2 years ago
  • 3.3.0-alpha.5                                ...           2 years ago
  • 3.3.0-alpha.4                                ...           2 years ago
  • 3.3.0-alpha.3                                ...           2 years ago
  • 3.3.0-alpha.2                                ...           2 years ago
  • 3.3.0-alpha.1                                ...           2 years ago
  • 3.2.47                                ...           2 years ago
  • 3.2.46                                ...           2 years ago
  • 3.2.45                                ...           2 years ago
  • 3.2.44                                ...           2 years ago
  • 3.2.43                                ...           2 years ago
  • 2.7.14                                ...           2 years ago
  • 3.2.42                                ...           2 years ago
  • 3.2.41                                ...           2 years ago
  • 2.7.13                                ...           2 years ago
  • 2.7.12                                ...           2 years ago
  • 2.7.11                                ...           2 years ago
  • 3.2.40                                ...           2 years ago
  • 3.2.39                                ...           2 years ago
  • 3.2.38                                ...           2 years ago
  • 2.7.10                                ...           2 years ago
  • 2.7.9                                ...           2 years ago
  • 2.7.8                                ...           2 years ago
  • 2.7.7                                ...           2 years ago
  • 2.7.6                                ...           2 years ago
  • 2.7.5                                ...           2 years ago
  • 2.7.4                                ...           2 years ago
  • 2.7.3                                ...           2 years ago
  • 2.7.2                                ...           2 years ago
  • 2.7.1                                ...           2 years ago
  • 2.7.0                                ...           2 years ago
  • 2.7.0-beta.8                                ...           2 years ago
  • 2.7.0-beta.7                                ...           2 years ago
  • 2.7.0-beta.6                                ...           2 years ago
  • 2.7.0-beta.5                                ...           3 years ago
  • 2.7.0-beta.4                                ...           3 years ago
  • 2.7.0-beta.3                                ...           3 years ago
  • 2.7.0-beta.2                                ...           3 years ago
  • 2.7.0-beta.1                                ...           3 years ago
  • 2.7.0-alpha.12                                ...           3 years ago
  • 2.7.0-alpha.11                                ...           3 years ago
  • 2.7.0-alpha.10                                ...           3 years ago
  • 2.7.0-alpha.9                                ...           3 years ago
  • 2.7.0-alpha.8                                ...           3 years ago
  • 2.7.0-alpha.7                                ...           3 years ago
  • 2.7.0-alpha.6                                ...           3 years ago
  • 3.2.37                                ...           3 years ago
  • 2.7.0-alpha.5                                ...           3 years ago
  • 2.7.0-alpha.4                                ...           3 years ago
  • 2.7.0-alpha.3                                ...           3 years ago
  • 2.7.0-alpha.2                                ...           3 years ago
  • 2.7.0-alpha.1                                ...           3 years ago
  • 3.2.36                                ...           3 years ago
  • 3.2.35                                ...           3 years ago
  • 3.2.34                                ...           3 years ago
  • 3.2.34-beta.1                                ...           3 years ago
  • 3.2.33                                ...           3 years ago
  • 3.2.32                                ...           3 years ago
  • 3.2.31                                ...           3 years ago
  • 3.2.30                                ...           3 years ago
  • 3.2.29                                ...           3 years ago
  • 3.2.28                                ...           3 years ago
  • 3.2.27                                ...           3 years ago
  • 3.2.26                                ...           3 years ago
  • 3.2.25                                ...           3 years ago
  • 3.2.24                                ...           3 years ago
  • 3.2.23                                ...           3 years ago
  • 3.2.22                                ...           3 years ago
  • 3.2.21                                ...           3 years ago
  • 3.2.20                                ...           3 years ago
  • 3.2.19                                ...           3 years ago
  • 3.2.18                                ...           3 years ago
  • 3.2.17                                ...           3 years ago
  • 3.2.16                                ...           3 years ago
  • 3.2.15                                ...           3 years ago
  • 3.2.14                                ...           3 years ago
  • 3.2.13                                ...           3 years ago
  • 3.2.12                                ...           3 years ago
  • 3.2.11                                ...           3 years ago
  • 3.2.10                                ...           3 years ago
  • 3.2.9                                ...           3 years ago
  • 3.2.8                                ...           3 years ago
  • 3.2.7                                ...           3 years ago
  • 3.2.6                                ...           3 years ago
  • 3.2.5                                ...           3 years ago
  • 3.2.4                                ...           3 years ago
  • 3.2.3                                ...           3 years ago
  • 3.2.2                                ...           3 years ago
  • 3.2.1                                ...           3 years ago
  • 3.2.0                                ...           3 years ago
  • 3.2.0-beta.8                                ...           3 years ago
  • 3.2.0-beta.7                                ...           3 years ago
  • 3.2.0-beta.6                                ...           3 years ago
  • 3.2.0-beta.5                                ...           3 years ago
  • 3.2.0-beta.4                                ...           3 years ago
  • 3.2.0-beta.3                                ...           3 years ago
  • 3.2.0-beta.2                                ...           3 years ago
  • 3.2.0-beta.1                                ...           3 years ago
  • 3.1.5                                ...           3 years ago
  • 3.1.4                                ...           3 years ago
  • 3.1.3                                ...           3 years ago
  • 3.1.2                                ...           4 years ago
  • 3.1.1                                ...           4 years ago
  • 3.1.0                                ...           4 years ago
  • 3.1.0-beta.7                                ...           4 years ago
  • 3.1.0-beta.6                                ...           4 years ago
  • 3.1.0-beta.5                                ...           4 years ago
  • 3.1.0-beta.4                                ...           4 years ago
  • 3.1.0-beta.3                                ...           4 years ago
  • 3.1.0-beta.2                                ...           4 years ago
  • 3.1.0-beta.1                                ...           4 years ago
  • 3.0.11                                ...           4 years ago
  • 3.0.10                                ...           4 years ago
  • 3.0.9                                ...           4 years ago
  • 3.0.8 [deprecated]           ...           4 years ago
  • 3.0.7                                ...           4 years ago
  • 3.0.6                                ...           4 years ago
  • 3.0.5                                ...           4 years ago
  • 3.0.4                                ...           4 years ago
  • 3.0.3                                ...           4 years ago
  • 3.0.2                                ...           4 years ago
  • 3.0.1                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 3.0.0-rc.13                                ...           4 years ago
  • 3.0.0-rc.12                                ...           4 years ago
  • 3.0.0-rc.11                                ...           4 years ago
  • 3.0.0-rc.10                                ...           4 years ago
  • 3.0.0-rc.9                                ...           4 years ago
  • 3.0.0-rc.8                                ...           4 years ago
  • 3.0.0-rc.7                                ...           4 years ago
  • 3.0.0-rc.6                                ...           4 years ago
  • 3.0.0-rc.5                                ...           4 years ago
  • 3.0.0-rc.4                                ...           4 years ago
  • 3.0.0-rc.3                                ...           4 years ago
  • 3.0.0-rc.2                                ...           4 years ago
  • 3.0.0-rc.1                                ...           4 years ago
  • 3.0.0-beta.24                                ...           4 years ago
  • 3.0.0-beta.23                                ...           4 years ago
  • 3.0.0-beta.22                                ...           4 years ago
  • 3.0.0-beta.21                                ...           4 years ago
  • 3.0.0-beta.20                                ...           4 years ago
  • 3.0.0-beta.19                                ...           4 years ago
  • 3.0.0-beta.18                                ...           4 years ago
  • 3.0.0-beta.17                                ...           4 years ago
  • 3.0.0-beta.16                                ...           4 years ago
  • 3.0.0-beta.15                                ...           5 years ago
  • 3.0.0-beta.14                                ...           5 years ago
  • 3.0.0-beta.13                                ...           5 years ago
  • 3.0.0-beta.12                                ...           5 years ago
  • 3.0.0-beta.11                                ...           5 years ago
  • 3.0.0-beta.10                                ...           5 years ago
  • 3.0.0-beta.9                                ...           5 years ago
  • 3.0.0-beta.8                                ...           5 years ago
  • 3.0.0-beta.7                                ...           5 years ago
  • 3.0.0-beta.6                                ...           5 years ago
  • 3.0.0-beta.5                                ...           5 years ago
  • 3.0.0-beta.4                                ...           5 years ago
  • 3.0.0-beta.3                                ...           5 years ago
  • 3.0.0-beta.2                                ...           5 years ago
  • 3.0.0-beta.1                                ...           5 years ago
  • 3.0.0-alpha.13                                ...           5 years ago
  • 3.0.0-alpha.12                                ...           5 years ago
  • 3.0.0-alpha.11                                ...           5 years ago
  • 3.0.0-alpha.10                                ...           5 years ago
  • 3.0.0-alpha.9                                ...           5 years ago
  • 3.0.0-alpha.8                                ...           5 years ago
  • 3.0.0-alpha.7                                ...           5 years ago
  • 3.0.0-alpha.6                                ...           5 years ago
  • 3.0.0-alpha.5                                ...           5 years ago
  • 3.0.0-alpha.4                                ...           5 years ago
  • 3.0.0-alpha.3                                ...           5 years ago
  • 3.0.0-alpha.2                                ...           5 years ago
  • 3.0.0-alpha.1                                ...           5 years ago
  • 3.0.0-alpha.0                                ...           5 years ago
Maintainers (1)
Downloads
Total 2
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dev Dependencies (10)

© 2010 - cnpmjs.org x YWFE | Home | YWFE