@pedrolamas/plugin-vue2 2.4.0
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/LICENSE +21 -0
- package/README.md +129 -0
- package/dist/index.cjs +1260 -0
- package/dist/index.d.cts +41 -0
- package/dist/index.d.mts +39 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.mjs +1248 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-present, Yuxi (Evan) You and contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# @pedrolamas/plugin-vue2 [](https://npmjs.com/package/@pedrolamas/plugin-vue2)
|
|
2
|
+
|
|
3
|
+
> [!CAUTION]
|
|
4
|
+
> Vue 2 has reached EOL, and this project is no longer actively maintained.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
> Note: this plugin requires Vite 8 (`vite >= 8.0.0`) and only works with Vue@^2.7.0.
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
// vite.config.js
|
|
12
|
+
import vue from '@pedrolamas/plugin-vue2'
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
plugins: [vue()]
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Options
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
export interface Options {
|
|
23
|
+
include?: string | RegExp | (string | RegExp)[]
|
|
24
|
+
exclude?: string | RegExp | (string | RegExp)[]
|
|
25
|
+
|
|
26
|
+
isProduction?: boolean
|
|
27
|
+
|
|
28
|
+
// options to pass on to vue/compiler-sfc
|
|
29
|
+
script?: Partial<Pick<SFCScriptCompileOptions, 'babelParserPlugins'>>
|
|
30
|
+
template?: Partial<
|
|
31
|
+
Pick<
|
|
32
|
+
SFCTemplateCompileOptions,
|
|
33
|
+
| 'compiler'
|
|
34
|
+
| 'compilerOptions'
|
|
35
|
+
| 'preprocessOptions'
|
|
36
|
+
| 'transpileOptions'
|
|
37
|
+
| 'transformAssetUrls'
|
|
38
|
+
| 'transformAssetUrlsOptions'
|
|
39
|
+
>
|
|
40
|
+
>
|
|
41
|
+
style?: Partial<Pick<SFCStyleCompileOptions, 'trim'>>
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Asset URL handling
|
|
46
|
+
|
|
47
|
+
When `@pedrolamas/plugin-vue2` compiles the `<template>` blocks in SFCs, it also converts any encountered asset URLs into ESM imports.
|
|
48
|
+
|
|
49
|
+
For example, the following template snippet:
|
|
50
|
+
|
|
51
|
+
```vue
|
|
52
|
+
<img src="../image.png" />
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Is the same as:
|
|
56
|
+
|
|
57
|
+
```vue
|
|
58
|
+
<script setup>
|
|
59
|
+
import _imports_0 from '../image.png'
|
|
60
|
+
</script>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```vue
|
|
64
|
+
<img :src="_imports_0" />
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
By default the following tag/attribute combinations are transformed, and can be configured using the `template.transformAssetUrls` option.
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
{
|
|
71
|
+
video: ['src', 'poster'],
|
|
72
|
+
source: ['src'],
|
|
73
|
+
img: ['src'],
|
|
74
|
+
image: ['xlink:href', 'href'],
|
|
75
|
+
use: ['xlink:href', 'href']
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Note that only attribute values that are static strings are transformed. Otherwise, you'd need to import the asset manually, e.g. `import imgUrl from '../image.png'`.
|
|
80
|
+
|
|
81
|
+
## Example for passing options to `vue/compiler-sfc`:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import vue from '@pedrolamas/plugin-vue2'
|
|
85
|
+
|
|
86
|
+
export default {
|
|
87
|
+
plugins: [
|
|
88
|
+
vue({
|
|
89
|
+
template: {
|
|
90
|
+
compilerOptions: {
|
|
91
|
+
// ...
|
|
92
|
+
},
|
|
93
|
+
transformAssetUrls: {
|
|
94
|
+
// ...
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Example for transforming custom blocks
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import vue from '@pedrolamas/plugin-vue2'
|
|
106
|
+
|
|
107
|
+
const vueI18nPlugin = {
|
|
108
|
+
name: 'vue-i18n',
|
|
109
|
+
transform(code, id) {
|
|
110
|
+
if (!/vue&type=i18n/.test(id)) {
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
if (/\.ya?ml$/.test(id)) {
|
|
114
|
+
code = JSON.stringify(require('js-yaml').load(code.trim()))
|
|
115
|
+
}
|
|
116
|
+
return `export default Comp => {
|
|
117
|
+
Comp.i18n = ${code}
|
|
118
|
+
}`
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export default {
|
|
123
|
+
plugins: [vue(), vueI18nPlugin]
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT
|