3.2024.0-02d8ec9 • Published 18 hours ago

@vue-vapor/compiler-sfc v3.2024.0-02d8ec9

Weekly downloads
-
License
MIT
Repository
github
Last release
18 hours ago

@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.

3.2024.0-02d8ec9

18 hours ago

3.2024.0-b58d6a9

10 days ago

3.2024.0-e1478e2

11 days ago

3.2024.0-2b0def3

11 days ago

3.2024.0-52c4cf0

11 days ago

3.2024.0-fd25071

11 days ago

3.2024.0-c4f6d0f

11 days ago

3.2024.0-25ff0df

13 days ago

3.2024.0-bfb5250

12 days ago

3.2024.0-8dea04b

13 days ago

3.2024.0-1168fd2

13 days ago

3.2024.0-4cfd4ce

13 days ago

3.2024.0-6f7d219

13 days ago

3.2024.0-273336c

13 days ago

3.2024.0-94ab8ce

13 days ago

3.2024.0-6958051

13 days ago

3.2024.0-098b6fc

13 days ago

3.2024.0-f4cc399

13 days ago

3.2024.0-fb58e65

14 days ago

3.2024.0-70ee69c

14 days ago

3.2024.0-e4df821

14 days ago

3.2024.0-d3a1df2

15 days ago

3.2024.0-a5d6457

15 days ago

3.2024.0-5c86b2a

15 days ago

3.2024.0-e42fecb

15 days ago

3.2024.0-05f4ade

15 days ago

3.2024.0-31e2c91

15 days ago

3.2024.0-caf6aeb

15 days ago

3.2024.0-7feda2e

15 days ago

3.2024.0-2d68429

15 days ago

3.2024.0-43fd261

15 days ago

3.2024.0-fedc46f

15 days ago

3.2024.0-aa5d87b

16 days ago

3.2024.0-d4f878e

16 days ago

3.2024.0-ce6aa06

16 days ago

3.2024.0-ae4ec30

16 days ago

3.2024.0-464b498

17 days ago

3.2024.0-31a9614

17 days ago

3.2024.0-cd58294

17 days ago

3.2024.0-521f3c7

17 days ago

3.2024.0-874dd8a

17 days ago

3.2024.0-4141c16

17 days ago

3.2024.0-dcaad1d

17 days ago

3.2024.0-7fe4712

19 days ago

3.2024.0-3ca2f21

20 days ago

3.2024.0-b3ad1c9

19 days ago

3.2024.0-b7b652e

19 days ago

3.2024.0-4baeb26

20 days ago

3.2024.0-63a2cd8

20 days ago

3.2024.0-2072ae2

21 days ago

3.2024.0-d6c5bcf

22 days ago

3.2024.0-e67e643

23 days ago

3.2024.0-7cad1d6

23 days ago

3.2024.0-d490bf2

23 days ago

3.2024.0-4352137

23 days ago

3.2024.0-4b5bd5b

23 days ago

3.2024.0-a2d0d4d

23 days ago

3.2024.0-f183394

23 days ago

3.2024.0-d286eed

23 days ago

3.2024.0-0013e82

24 days ago

3.2024.0-b9b3e02

24 days ago

3.2024.0-37df043

24 days ago

3.2024.0-1f28ae1

24 days ago

3.2024.0-2fa93ac

24 days ago

3.2024.0-c5fdd37

24 days ago

3.2024.0-1af1f40

26 days ago

3.2024.0-7548865

25 days ago

3.2024.0-af1581b

25 days ago

3.2024.0-66fc3b2

25 days ago

3.2024.0-a68445b

26 days ago

3.2024.0-761f785

26 days ago

3.2024.0-5a599d6

28 days ago

3.2024.0-b447ace

27 days ago

3.2024.0-e640ec6

27 days ago

3.2024.0-b6bde54

28 days ago

3.2024.0-9e0cd20

29 days ago

3.2024.0-a49b6f9

29 days ago

3.2024.0-bdc4322

29 days ago

3.2024.0-22c0538

29 days ago

3.2024.0-a0bd0e9

1 month ago

3.2024.0-38c9d9f

1 month ago

3.2024.0-b961c43

1 month ago

3.2024.0-17e46d4

1 month ago

3.2024.0-f75e834

1 month ago

3.2024.0-e760d68

1 month ago

3.2024.0-98bae0c

1 month ago

3.2024.0-9a33d79

1 month ago

3.2024.0-6c99c7a

1 month ago

3.2024.0-3aba5c9

1 month ago

3.2024.0-dccd6e3

1 month ago

3.2024.0-2e39f3e

1 month ago

3.2024.0-dd6a69b

1 month ago

3.2024.0-157de30

1 month ago

3.2024.0-bb8da6d

1 month ago

3.2024.0-92a4d56

1 month ago

3.2024.0-d6b652a

1 month ago

3.2024.0-db140a1

1 month ago

3.2024.0-339fced

1 month ago

3.2024.0-acc8324

1 month ago

3.2024.0-9f8bf4f

2 months ago

3.2024.0-486f2a8

2 months ago

3.2024.0-5a28a15

2 months ago

3.2024.0-9afaf0d

2 months ago

3.2024.0-100e3fd

2 months ago

3.2024.0-77d74f0

2 months ago

3.2024.0-ba17fb9

2 months ago

3.2024.0-cd8d756

2 months ago

3.2024.0-af516d0

2 months ago

3.2024.0-fe35414

2 months ago

3.2024.0-5b76208

2 months ago

3.2024.0-3992ba5

2 months ago

3.2024.0-08cc2bc

2 months ago

3.2024.0-f1f8b42

2 months ago

3.2024.0-38af9aa

2 months ago

3.2024.0-c633534

2 months ago

3.2024.0-35feb3c

2 months ago

3.2024.0-4d3a8e8

2 months ago

3.2024.0-05774e5

2 months ago

3.2024.0-cf18747

2 months ago

3.2024.0-ed6b171

2 months ago

3.2024.0-9a2c12e

2 months ago

3.2024.0-9dfc966

2 months ago

3.2024.0-5c9a151

2 months ago

3.2024.0-bd888b9

2 months ago

3.2024.0-339e674

2 months ago

3.2024.0-463ae38

2 months ago

3.2024.0-d8b6bcb

2 months ago

3.2024.0-c41eed2

2 months ago

3.2024.0-f3df266

2 months ago

3.2024.0-0169ec4

2 months ago

3.2024.0-ebde516

2 months ago

3.2024.0-31e19df

2 months ago

3.2024.0-b689fa6

2 months ago

3.2024.0-064e6d4

2 months ago

3.2024.0-6a7957d

2 months ago

3.2024.0-d12c2ac

2 months ago

3.2024.0-2de2c1d

2 months ago

3.2024.0-268a2c4

2 months ago

3.2024.0-64e8368

2 months ago

3.2024.0-34ca9f5

2 months ago

3.2024.0-38e167c

2 months ago

3.2024.0-6fc5cfb

2 months ago

3.2024.0-eb3d1fc

2 months ago

3.2024.0-5609644

2 months ago

3.2024.0-2661cb2

2 months ago

3.2024.0-9d03e6e

2 months ago

3.2024.0-12df345

2 months ago

3.2024.0-71c9d27

2 months ago

3.2024.0-fb8609d

2 months ago

3.2024.0-0159af9

2 months ago

3.2024.0-1e00d6c

2 months ago

3.2024.0-4676188

2 months ago

3.2024.0-5d15314

2 months ago

3.2024.0-2b3962f

2 months ago

3.2024.0-2ec05d8

2 months ago

3.2024.0-d282af9

2 months ago

3.2024.0-3e0d646

2 months ago

3.2024.0-fd2d9ff

2 months ago

3.2024.0-e967ed1

2 months ago

3.2024.0-83e4102

2 months ago

3.2024.0-463b47e

2 months ago

3.2024.0-808d17d

2 months ago

3.2024.0-c79629f

2 months ago

3.2024.0-7e0f15f

2 months ago

3.2024.0-421eba3

2 months ago

3.2024.0-6461c0f

2 months ago

3.2024.0-827fced

2 months ago

3.2024.0-b4da5a8

2 months ago

3.2024.0-b4aa5f9

2 months ago

3.2024.0-9412c20

2 months ago

3.2024.0-246badc

2 months ago

3.2024.0-280b8cb

2 months ago

3.2024.0-ebd3710

2 months ago

3.2024.0-b71cc27

2 months ago

3.2024.0-ccfecc9

2 months ago

3.2024.0-03d1d0a

2 months ago

3.2024.0-d20cf6d

2 months ago

3.2024.0-11b99ba

2 months ago

3.2024.0-d8880c8

2 months ago

3.2024.0-61ada62

2 months ago

3.2024.0-f4768bc

2 months ago

3.2024.0-d3ca3f7

2 months ago

3.2024.0-91997bb

2 months ago

3.2024.0-26ad63b

2 months ago

3.2024.0-b925c62

2 months ago

3.2024.0-ffb79a0

2 months ago

3.2024.0-ccd3f39

2 months ago

3.2024.0-5a0365d

2 months ago

3.2024.0-7f86144

2 months ago

3.2024.0-5a0bc11

2 months ago

3.2024.0-320e8f7

2 months ago

3.2024.0-76fbceb

2 months ago

3.2024.0-9cc0a2b

2 months ago

3.2024.0-4af8e87

2 months ago

3.2024.0-04fe609

3 months ago

3.2024.0-83641f7

3 months ago

3.2024.0-0e57653

3 months ago

3.2024.0-cb53a1e

3 months ago

3.2024.0-fac30af

3 months ago

3.2024.0-2c15171

3 months ago

3.2024.0-65909f6

3 months ago

3.2024.0-2075042

3 months ago

3.2024.0-d7bd6c9

3 months ago

3.2024.0-d9907ef

3 months ago

3.2024.0-ff943f4

3 months ago

3.2024.0-7072932

3 months ago

3.2024.0-0e0ee5b

3 months ago

3.2024.0-fb3e8ee

3 months ago

3.2024.0-d58497f

3 months ago

3.2024.0-4c9d891

3 months ago

3.2024.0-a87d212

3 months ago

3.2024.0-26f29b2

3 months ago

3.2024.0-e5c1f8d

3 months ago

3.2024.0-ddaf23e

3 months ago

3.2024.0-004edd3

3 months ago

3.2024.0-c1d9b64

3 months ago

3.2024.0-e91dde5

3 months ago

3.2024.0-c9db3fa

3 months ago

3.2024.0-669fec8

3 months ago

3.2024.0-5819dc9

3 months ago

3.2024.0-7aae631

3 months ago

3.2024.0-23653cc

3 months ago

3.2024.0-36b6e7e

3 months ago

3.2024.0-fa0ca8a

3 months ago

3.2024.0-531f4f0

3 months ago

3.2024.0-ba29b4c

3 months ago

3.2024.0-6ced902

3 months ago

3.2024.0-b11ecbd

3 months ago

3.2024.0-1710bfd

3 months ago

3.2024.0-3a6a1dd

3 months ago

3.2024.0-ea5c361

3 months ago

3.2024.0-6c25fb6

3 months ago

3.2024.0-7fd7742

3 months ago

3.2024.0-e10f7d1

3 months ago

3.2024.0-95b08e8

3 months ago

3.2024.0-66cea4b

3 months ago

3.2024.0-3d10925

3 months ago

3.2024.0-bf5f7c3

3 months ago

3.2024.0-f7080ef

3 months ago

3.2024.0-afa7ee2

3 months ago

3.20240210.0

3 months ago

3.2024.0-3550765

3 months ago

3.20240210.1

3 months ago

3.0.0-35f69d1

3 months ago

3.2024.1

3 months ago

3.2024.0

3 months ago

3.2024.0-9e029e8

3 months ago

3.2024.0-2486d99

3 months ago

3.2024.0-184d72e

3 months ago

3.2024.0-8bd92c9

3 months ago

3.2024.0-b5e12ea

3 months ago

3.20240209.0

3 months ago

0.20240209.3

3 months ago

0.20240209.2

3 months ago

0.20240209.1

3 months ago

0.20240209.0

3 months ago