You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copy file name to clipboardExpand all lines: README.md
+71-61Lines changed: 71 additions & 61 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,96 +4,106 @@ Use the `mix` helper function to get the correct path to your versioned CSS and
4
4
5
5
## Installation
6
6
7
-
Copy or link the `laravel-mix-kirby` directory to `site/plugins` or use the [Kirby CLI](https://github.com/getkirby/cli): `kirby plugin:install diverently/laravel-mix-kirby`.
7
+
### Download
8
8
9
-
You should also install [Laravel Mix](https://github.com/JeffreyWay/laravel-mix), otherwise this plugin is pretty useless ;-) See the [installation guide](https://github.com/JeffreyWay/laravel-mix/blob/master/docs/installation.md) for further information, though it's actually pretty straight forward:
9
+
Download and copy this repository to `site/plugins/laravel-mix-kirby`.
10
10
11
-
1. If you haven't already, create a `package.json` inside your project root: `npm init -y`
You should also install **Laravel Mix**, otherwise this plugin is pretty useless ;-) See the [installation guide](https://laravel-mix.com/docs/4.0/installation) for further information, though it's actually pretty straight forward:
30
26
31
-
## Usage
27
+
## Setup
32
28
33
-
### Initial setup
34
-
Depending on your preferred project structure you have to make some changes to your `webpack.mix.js`. You should set the paths where the `mix-manifest.json` as well as the CSS and JS files will be stored.
35
-
I keep my source files outside the `kirby` (or `dist`) directory but you may have a different setup. Mine looks as follows:
29
+
In your `site/config/config.php` you can set two options to make this helper work with your specific setup:
36
30
37
-
```
38
-
- kirby (or dist)
39
-
|- assets
40
-
|- css
41
-
|- js
42
-
|- ...
43
-
- src
44
-
|- css
45
-
|- main.scss
46
-
|- ...
47
-
|- js
48
-
|- main.js
49
-
|- ...
50
-
|- ...
51
-
```
31
+
### `diverently.laravel-mix-kirby.manifestPath`
52
32
53
-
With that setup I start with the following `webpack.mix.js`:
33
+
This is where the helper function will look for the manifest created by Laravel Mix.
54
34
55
-
```js
56
-
mix.setPublicPath('kirby/assets/')
57
-
mix.browserSync('my-website.dev')
58
-
mix.sourceMaps()
59
-
.js('src/js/main.js', 'kirby/assets/js/')
60
-
.sass('src/css/main.scss', 'kirby/assets/css')
61
-
.version();
62
-
```
35
+
Default: `assets/mix-manifest.json`
63
36
64
-
When you run `npm run dev` your `main.js` and `main.css` files will be created. They will also be versioned which makes referencing them via the standard `css()` and `js()` methods pretty tedious. That’s where the helper function comes in (and thus this entire plugin).
This will be prepended to the individual file paths given to the `mix()` function when creating the final HTML tags.
40
+
41
+
Default: `assets`
42
+
43
+
## Options
65
44
66
45
### `mix()` helper function
67
-
The `mix()` helper function reads the `mix-manifest.json` file and returns the right HTML tag with the correct (versioned) path to the requested file. In our example we would call it like so:
46
+
47
+
The `mix()` helper function reads the `mix-manifest.json` file and returns the right HTML tag with the correct path to the requested file. In our example we would call it like so:
68
48
69
49
```php
70
-
// snippets/header.php
50
+
<html>
71
51
<head>
72
-
// ...
73
-
74
-
<?= mix('/css/main.css') ?>
52
+
// ...
53
+
<?php echo mix('/main.css') ?>
75
54
</head>
76
-
77
-
// snippets/footer.php
78
-
<?= mix('/js/main.js') ?>
55
+
<body>
56
+
// ...
57
+
<?php echo mix('/main.js') ?>
79
58
</body>
80
59
</html>
81
60
```
82
61
83
62
And that's it, actually.
84
63
85
-
### Options
64
+
##Development
86
65
87
-
In your `site/config/config.php` you can set two options to make this helper work with your specific setup:
66
+
1. If you haven't already, create a `package.json` inside your project root: `npm init -y`
> The idea behind this originally came from the `mix` Blade helper created for the Laravel framework. This is merely just a "translation" for the Kirby CMS, only that it also generates the correct HTML tag depending on what file type you request.
109
+
> The idea behind this originally came from the `mix` Blade helper created for the Laravel framework. This is merely a "translation" for the Kirby CMS, only that it also generates the correct HTML tag depending on what file type you request.
0 commit comments