Skip to content

Commit 09e5da4

Browse files
committed
added assets & Vite support
1 parent a4a1a5d commit 09e5da4

File tree

8 files changed

+64
-6
lines changed

8 files changed

+64
-6
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
www/assets

app/Presentation/@layout.latte

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
<meta name="viewport" content="width=device-width">
66

77
<title>{ifset title}{include title|stripHtml} | {/ifset}Nette Web</title>
8+
9+
{asset? 'main.js'}
810
</head>
911

1012
<body>
1113
<div n:foreach="$flashes as $flash" n:class="flash, $flash->type">{$flash->message}</div>
1214

1315
{include content}
14-
15-
{block scripts}
16-
<script src="https://unpkg.com/nette-forms@3"></script>
17-
{/block}
1816
</body>
1917
</html>

assets/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Initialize Nette Forms on page load
2+
import netteForms from 'nette-forms';
3+
4+
netteForms.initOnLoad();

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"require": {
88
"php": ">= 8.1",
99
"nette/application": "^3.2.3",
10-
"nette/bootstrap": "^3.2",
10+
"nette/assets": "^1.0.0",
11+
"nette/bootstrap": "^3.2.6",
1112
"nette/caching": "^3.2",
1213
"nette/database": "^3.2",
1314
"nette/di": "^3.2",

config/common.neon

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# see https://doc.nette.org/en/configuring
2+
13
parameters:
24

35

@@ -21,6 +23,13 @@ latte:
2123
- App\Presentation\Accessory\LatteExtension
2224

2325

26+
assets:
27+
mapping:
28+
default:
29+
path: assets
30+
# type: vite # Uncomment to activate Vite for asset building
31+
32+
2433
di:
2534
export:
2635
parameters: no

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"type": "module",
3+
"dependencies": {
4+
"nette-forms": "^3.3"
5+
},
6+
"devDependencies": {
7+
"@nette/vite-plugin": "^1.0.1",
8+
"vite": "^6.3.5"
9+
},
10+
"scripts": {
11+
"dev": "vite",
12+
"build": "vite build"
13+
}
14+
}

readme.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ follow [these instructions](https://doc.nette.org/composer). Then, run:
3030
Ensure the `temp/` and `log/` directories are writable.
3131

3232

33+
Asset Building with Vite
34+
------------------------
35+
36+
This project supports Vite for asset building, which is recommended but optional. To activate Vite:
37+
38+
1. Uncomment the `type: vite` line in the `common.neon` configuration file under the assets mapping section.
39+
2. Then set up and build the assets:
40+
41+
npm install
42+
npm run build
43+
44+
3345
Web Server Setup
3446
----------------
3547

@@ -49,4 +61,4 @@ Minimal Skeleton
4961
----------------
5062

5163
For demonstrating issues or similar tasks, rather than starting a new project, use
52-
this [minimal skeleton](https://github.com/nette/web-project/tree/minimal).
64+
[minimal skeleton](https://github.com/nette/web-project/tree/minimal).

vite.config.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { defineConfig } from 'vite';
2+
import nette from '@nette/vite-plugin';
3+
4+
export default defineConfig({
5+
plugins: [
6+
nette({
7+
input: 'main.js',
8+
}),
9+
],
10+
11+
build: {
12+
emptyOutDir: true,
13+
},
14+
15+
css: {
16+
devSourcemap: true,
17+
},
18+
});

0 commit comments

Comments
 (0)