Add versioning to CSS and JS assets
This commit is contained in:
parent
f5c66052cb
commit
036818d023
6 changed files with 43 additions and 9 deletions
|
|
@ -1,4 +1,32 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
/** @var $container \Illuminate\Container\Container */
|
||||
/** @var $jigsaw \TightenCo\Jigsaw\Jigsaw */
|
||||
/** @var $jigsaw \TightenCo\Jigsaw\Jigsaw */
|
||||
|
||||
function mix($path, $manifestDirectory = '')
|
||||
{
|
||||
static $manifests = [];
|
||||
if (! Str::startsWith($path, '/')) {
|
||||
$path = "/{$path}";
|
||||
}
|
||||
if ($manifestDirectory && ! Str::startsWith($manifestDirectory, '/')) {
|
||||
$manifestDirectory = "/{$manifestDirectory}";
|
||||
}
|
||||
|
||||
$manifestPath = public_path($manifestDirectory.'/mix-manifest.json');
|
||||
|
||||
if (! isset($manifests[$manifestPath])) {
|
||||
if (! file_exists($manifestPath)) {
|
||||
throw new Exception('The Mix manifest does not exist.');
|
||||
}
|
||||
$manifests[$manifestPath] = json_decode(file_get_contents($manifestPath), true);
|
||||
}
|
||||
$manifest = $manifests[$manifestPath];
|
||||
if (! isset($manifest[$path])) {
|
||||
throw new InvalidArgumentException("Unable to locate Mix file: {$path}.");
|
||||
}
|
||||
return new HtmlString($manifestDirectory.$manifest[$path]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"/source/js/app.js": "/source/js/app.js",
|
||||
"/source/css/main.css": "/source/css/main.css"
|
||||
}
|
||||
|
|
@ -19,9 +19,9 @@
|
|||
@import url("https://use.typekit.net/iqy1okj.css");
|
||||
</style>
|
||||
{{-- <link rel="stylesheet" href="https://use.typekit.net/iqy1okj.css"> --}}
|
||||
<link rel="stylesheet" href="/css/main.css">
|
||||
<link rel="stylesheet" href="{{ mix('/css/main.css') }}">
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
|
||||
<script src="/js/nav.js"></script>
|
||||
<script src="{{ mix('/js/nav.js') }}"></script>
|
||||
|
||||
</head>
|
||||
<body class="font-sans font-normal text-slate-darker leading-normal">
|
||||
|
|
@ -190,7 +190,7 @@
|
|||
<div id="app">
|
||||
@yield('body')
|
||||
</div>
|
||||
<script src="/js/app.js"></script>
|
||||
<script src="{{ mix('/js/app.js') }}"></script>
|
||||
<script src="/js/prism.js"></script>
|
||||
<script>
|
||||
anchors.options = { placement: 'left', class: 'text-slate-light' };
|
||||
|
|
|
|||
5
docs/source/mix-manifest.json
Normal file
5
docs/source/mix-manifest.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"/js/app.js": "/js/app.js?id=829229e23347506d9965",
|
||||
"/js/nav.js": "/js/nav.js?id=d3b9e827e277824739e0",
|
||||
"/css/main.css": "/css/main.css?id=4501af3f10b009fbb9a1"
|
||||
}
|
||||
|
|
@ -3,12 +3,17 @@ const tailwind = require('./../lib/index.js')
|
|||
const config = require('./tailwind.js')
|
||||
const fs = require('fs')
|
||||
|
||||
mix.setPublicPath('source/');
|
||||
|
||||
fs.writeFileSync('./tailwind.json', JSON.stringify(config))
|
||||
|
||||
mix.js('source/_assets/js/app.js', 'source/js')
|
||||
mix
|
||||
.js('source/_assets/js/nav.js', 'source/js')
|
||||
.js('source/_assets/js/app.js', 'source/js')
|
||||
.less('source/_assets/less/main.less', 'source/css')
|
||||
.options({
|
||||
postCss: [
|
||||
tailwind('tailwind.js'),
|
||||
]
|
||||
})
|
||||
.version()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue