@vuebro/loader-sfc 2.3.11 â 2.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -6
- package/dist/loader-sfc.d.ts +5 -5
- package/dist/loader-sfc.esm-browser.prod.js +21566 -21561
- package/dist/loader-sfc.js +27 -23
- package/package.json +3 -5
package/README.md
CHANGED
|
@@ -2,27 +2,47 @@
|
|
|
2
2
|
|
|
3
3
|
Vue3 Single File Component (SFC) loader. Load .vue files directly from your browser without any build step.
|
|
4
4
|
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ð Load Vue 3 SFCs directly in the browser at runtime
|
|
8
|
+
- ⥠No build step required - perfect for dynamic component loading
|
|
9
|
+
- ð ïļ Supports TypeScript and JSX
|
|
10
|
+
- ðĶ Lightweight and efficient
|
|
11
|
+
- ð§ Compatible with Vue's `defineAsyncComponent`
|
|
12
|
+
|
|
5
13
|
## Installation
|
|
6
14
|
|
|
7
|
-
Install `@vuebro/loader-sfc` with npm
|
|
15
|
+
Install `@vuebro/loader-sfc` with npm:
|
|
8
16
|
|
|
9
17
|
```bash
|
|
10
18
|
npm install @vuebro/loader-sfc
|
|
11
19
|
```
|
|
12
20
|
|
|
13
|
-
|
|
21
|
+
Or with yarn:
|
|
14
22
|
|
|
15
|
-
|
|
23
|
+
```bash
|
|
24
|
+
yarn add @vuebro/loader-sfc
|
|
25
|
+
```
|
|
16
26
|
|
|
17
|
-
|
|
27
|
+
Or with pnpm:
|
|
18
28
|
|
|
19
|
-
```
|
|
29
|
+
```bash
|
|
30
|
+
pnpm add @vuebro/loader-sfc
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
### Basic Usage
|
|
36
|
+
|
|
37
|
+
To load .vue files dynamically at runtime just use the `loadModule` function:
|
|
38
|
+
|
|
39
|
+
```vue
|
|
20
40
|
<script setup>
|
|
21
41
|
import { defineAsyncComponent } from "vue";
|
|
22
42
|
import loadModule from "@vuebro/loader-sfc";
|
|
23
43
|
|
|
24
44
|
const AdminPage = defineAsyncComponent(() =>
|
|
25
|
-
loadModule(
|
|
45
|
+
loadModule("./components/AdminPageComponent.vue"),
|
|
26
46
|
);
|
|
27
47
|
</script>
|
|
28
48
|
|
|
@@ -31,4 +51,83 @@ const AdminPage = defineAsyncComponent(() =>
|
|
|
31
51
|
</template>
|
|
32
52
|
```
|
|
33
53
|
|
|
54
|
+
### Advanced Usage with Configuration
|
|
55
|
+
|
|
56
|
+
You can pass configuration options to customize the compilation process:
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
import { defineAsyncComponent } from "vue";
|
|
60
|
+
import loadModule from "@vuebro/loader-sfc";
|
|
61
|
+
|
|
62
|
+
const MyComponent = defineAsyncComponent(() =>
|
|
63
|
+
loadModule("./components/MyComponent.vue", {
|
|
64
|
+
scriptOptions: {
|
|
65
|
+
templateOptions: {
|
|
66
|
+
compilerOptions: {
|
|
67
|
+
expressionPlugins: ["typescript"], // Additional Babel plugins
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
parseOptions: {
|
|
72
|
+
// Options for the SFC parser
|
|
73
|
+
},
|
|
74
|
+
styleOptions: {
|
|
75
|
+
// Options for style compilation
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
|
+
);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## API
|
|
82
|
+
|
|
83
|
+
### `loadModule(filename: string, options?: LoadModuleOptions)`
|
|
84
|
+
|
|
85
|
+
Loads and compiles a Vue SFC file at runtime.
|
|
86
|
+
|
|
87
|
+
#### Parameters
|
|
88
|
+
|
|
89
|
+
- `filename` (string): Path to the .vue file to load
|
|
90
|
+
- `options` (LoadModuleOptions, optional): Configuration options for compilation
|
|
91
|
+
|
|
92
|
+
#### Options
|
|
93
|
+
|
|
94
|
+
- `scriptOptions`: Options for script compilation
|
|
95
|
+
- `templateOptions`: Options for template compilation
|
|
96
|
+
- `compilerOptions`: Vue template compiler options
|
|
97
|
+
- `expressionPlugins`: Additional Babel parser plugins (e.g., 'typescript', 'jsx')
|
|
98
|
+
- `parseOptions`: Options for SFC parsing
|
|
99
|
+
- `styleOptions`: Options for style compilation (e.g., scss, less)
|
|
100
|
+
|
|
101
|
+
## Requirements
|
|
102
|
+
|
|
103
|
+
- Vue 3.x
|
|
104
|
+
- Modern browser that supports ES modules and dynamic imports
|
|
105
|
+
|
|
106
|
+
## Performance Considerations
|
|
107
|
+
|
|
108
|
+
- The first load of a component will be slower as it needs to fetch and compile the SFC
|
|
109
|
+
- Subsequent loads of the same component will be faster due to browser caching
|
|
110
|
+
- Styles are injected into the document once per component and cached by a hash of the filename
|
|
111
|
+
- Consider using this loader for truly dynamic components, not for all components in your application
|
|
112
|
+
|
|
113
|
+
## Building and Development
|
|
114
|
+
|
|
115
|
+
To build the project locally:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
npm run build
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
To lint the code:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
npm run lint
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Examples
|
|
128
|
+
|
|
34
129
|
A simple example of using `@vuebro/loader-sfc` in a template Vue 3 + TypeScript + Vite application for dynamic loading and compilation of an SFC module during application runtime in the browser can be found in the repository: [loader-sfc-example](https://github.com/vuebro/loader-sfc-example)
|
|
130
|
+
|
|
131
|
+
## License
|
|
132
|
+
|
|
133
|
+
This project is licensed under the AGPL-3.0-only License.
|
package/dist/loader-sfc.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { SFCAsyncStyleCompileOptions,
|
|
2
|
-
declare const _default: (filename: string, {
|
|
3
|
-
parseOptions?: Partial<SFCParseOptions>;
|
|
4
|
-
scriptOptions?: Partial<SFCScriptCompileOptions>;
|
|
1
|
+
import type { SFCAsyncStyleCompileOptions, SFCScriptCompileOptions, SFCParseOptions } from "vue/compiler-sfc";
|
|
2
|
+
declare const _default: (filename: string, { scriptOptions: { templateOptions: { compilerOptions: { expressionPlugins, ...restCompilerOptions }, ...restTemplateOptions }, ...restScriptOptions }, parseOptions, styleOptions, }?: {
|
|
5
3
|
styleOptions?: Partial<SFCAsyncStyleCompileOptions>;
|
|
6
|
-
|
|
4
|
+
scriptOptions?: Partial<SFCScriptCompileOptions>;
|
|
5
|
+
parseOptions?: Partial<SFCParseOptions>;
|
|
6
|
+
} | undefined) => Promise<{
|
|
7
7
|
__scopeId: string;
|
|
8
8
|
}>;
|
|
9
9
|
export default _default;
|