@vituum/vite-plugin-latte 0.1.8 → 0.1.11
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 +26 -1
- package/handler.js +1 -1
- package/index.js +22 -16
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
# ⚡️☕ ViteLatte
|
|
5
5
|
|
|
6
6
|
```js
|
|
7
|
+
import latte from '@vituum/vite-plugin-latte'
|
|
8
|
+
|
|
7
9
|
export default {
|
|
8
10
|
plugins: [
|
|
9
11
|
latte({
|
|
@@ -16,12 +18,22 @@ export default {
|
|
|
16
18
|
tags: {},
|
|
17
19
|
globals: {
|
|
18
20
|
template: 'playground/templates/Layout/Main.latte'
|
|
21
|
+
},
|
|
22
|
+
data: '*.json',
|
|
23
|
+
isStringFilter: undefined,
|
|
24
|
+
filetypes: {
|
|
25
|
+
html: /.(json.html|latte.json.html|latte.html)$/,
|
|
26
|
+
json: /.(json.latte.html)$/
|
|
19
27
|
}
|
|
20
28
|
})
|
|
21
29
|
]
|
|
22
30
|
}
|
|
23
31
|
```
|
|
24
32
|
|
|
33
|
+
Read the [docs](https://vituum.dev/config/integrations-options.html#vituum-latte) to learn more about the plugin options.
|
|
34
|
+
|
|
35
|
+
## Basic usage
|
|
36
|
+
|
|
25
37
|
```html
|
|
26
38
|
<!-- index.html -->
|
|
27
39
|
<script type="application/json">
|
|
@@ -31,9 +43,22 @@ export default {
|
|
|
31
43
|
}
|
|
32
44
|
</script>
|
|
33
45
|
```
|
|
46
|
+
or
|
|
47
|
+
```html
|
|
48
|
+
<!-- index.latte.html with index.latte.json -->
|
|
49
|
+
{$title}
|
|
50
|
+
```
|
|
51
|
+
or
|
|
52
|
+
```html
|
|
53
|
+
<!-- index.latte.html or index.latte.json.html -->
|
|
54
|
+
{
|
|
55
|
+
"template": "path/to/template.latte",
|
|
56
|
+
"title": "Hello world"
|
|
57
|
+
}
|
|
58
|
+
```
|
|
34
59
|
|
|
35
60
|
### Requirements
|
|
36
61
|
|
|
37
62
|
- [Node.js LTS (16.x)](https://nodejs.org/en/download/)
|
|
38
|
-
- [NPM (8.x)](https://www.npmjs.com/package/npm) or [Yarn (2.x)](https://yarnpkg.com/)
|
|
39
63
|
- [PHP (8.x)](https://www.php.net/) or [Docker PHP (8.x)](https://hub.docker.com/_/php)
|
|
64
|
+
- [Vite](https://vitejs.dev/) or [Vituum](https://vituum.dev/)
|
package/handler.js
CHANGED
package/index.js
CHANGED
|
@@ -7,13 +7,19 @@ import FastGlob from 'fast-glob'
|
|
|
7
7
|
import lodash from 'lodash'
|
|
8
8
|
|
|
9
9
|
const defaultParams = {
|
|
10
|
+
reload: true,
|
|
11
|
+
root: null,
|
|
10
12
|
bin: 'php',
|
|
11
13
|
filters: {},
|
|
12
14
|
functions: {},
|
|
13
15
|
tags: {},
|
|
14
16
|
globals: {},
|
|
15
17
|
data: '',
|
|
16
|
-
isStringFilter: undefined
|
|
18
|
+
isStringFilter: undefined,
|
|
19
|
+
filetypes: {
|
|
20
|
+
html: /.(json.html|latte.json.html|latte.html)$/,
|
|
21
|
+
json: /.(json.latte.html)$/
|
|
22
|
+
}
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
const execSync = (cmd) => {
|
|
@@ -78,27 +84,26 @@ const latte = (params = {}) => {
|
|
|
78
84
|
|
|
79
85
|
return {
|
|
80
86
|
_params: params,
|
|
81
|
-
name: 'vite-plugin-latte',
|
|
87
|
+
name: '@vituum/vite-plugin-latte',
|
|
82
88
|
config: ({ root }) => {
|
|
83
|
-
params.root
|
|
89
|
+
if (!params.root) {
|
|
90
|
+
params.root = root
|
|
91
|
+
}
|
|
84
92
|
},
|
|
85
93
|
transformIndexHtml: {
|
|
86
94
|
enforce: 'pre',
|
|
87
95
|
async transform(content, { path, filename, server }) {
|
|
96
|
+
path = path.replace('?raw', '')
|
|
97
|
+
filename = filename.replace('?raw', '')
|
|
98
|
+
|
|
88
99
|
if (
|
|
89
|
-
!
|
|
90
|
-
!
|
|
91
|
-
!
|
|
92
|
-
!path.endsWith('.latte') &&
|
|
93
|
-
!content.startsWith('<script type="application/json"')
|
|
100
|
+
!params.filetypes.html.test(path) &&
|
|
101
|
+
!params.filetypes.json.test(path) &&
|
|
102
|
+
!content.startsWith('<script type="application/json" data-format="latte"')
|
|
94
103
|
) {
|
|
95
104
|
return content
|
|
96
105
|
}
|
|
97
106
|
|
|
98
|
-
if (content.startsWith('<script type="application/json"') && !content.includes('data-format="latte"')) {
|
|
99
|
-
return content
|
|
100
|
-
}
|
|
101
|
-
|
|
102
107
|
if (typeof params.isStringFilter === 'function' && params.isStringFilter(filename)) {
|
|
103
108
|
params.isString = true
|
|
104
109
|
} else {
|
|
@@ -117,18 +122,19 @@ const latte = (params = {}) => {
|
|
|
117
122
|
type: 'error',
|
|
118
123
|
err: {
|
|
119
124
|
message: renderLatte.output,
|
|
120
|
-
plugin: 'vite-plugin-latte'
|
|
125
|
+
plugin: '@vituum/vite-plugin-latte'
|
|
121
126
|
}
|
|
122
127
|
})
|
|
123
|
-
|
|
124
|
-
return
|
|
125
128
|
}
|
|
126
129
|
|
|
127
130
|
return renderLatte.output
|
|
128
131
|
}
|
|
129
132
|
},
|
|
130
133
|
handleHotUpdate({ file, server }) {
|
|
131
|
-
if (
|
|
134
|
+
if (
|
|
135
|
+
(typeof params.reload === 'function' && params.reload(file)) ||
|
|
136
|
+
(typeof params.reload === 'boolean' && params.reload && (params.filetypes.html.test(file) || params.filetypes.json.test(file)))
|
|
137
|
+
) {
|
|
132
138
|
server.ws.send({ type: 'full-reload' })
|
|
133
139
|
}
|
|
134
140
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vituum/vite-plugin-latte",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"lodash": "^4.17.21"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"vite": "^3.0.
|
|
17
|
-
"eslint": "^8.
|
|
16
|
+
"vite": "^3.0.9",
|
|
17
|
+
"eslint": "^8.23.0",
|
|
18
18
|
"eslint-config-standard": "^17.0.0"
|
|
19
19
|
},
|
|
20
20
|
"files": [
|