Asset compilation improvements

This commit is contained in:
Chris Kankiewicz
2020-01-07 11:54:23 -07:00
parent 5e6e04fbe0
commit 7b5e2c5994
6 changed files with 43 additions and 19 deletions

View File

@@ -56,7 +56,7 @@ class TwigProvider
);
foreach (self::VIEW_FUNCTIONS as $function) {
$function = new $function($this->config);
$function = new $function($this->container, $this->config);
$twig->getEnvironment()->addFunction(
new TwigFunction($function->name(), $function)

View File

@@ -2,6 +2,8 @@
namespace App\ViewFunctions;
use Tightenco\Collect\Support\Collection;
class Asset extends ViewFunction
{
/** @const Constant description */
@@ -19,6 +21,24 @@ class Asset extends ViewFunction
*/
public function __invoke(string $path): string
{
return self::ASSET_PATH . $path;
$assetPath = self::ASSET_PATH . $path;
if ($this->mixManifest()->has($assetPath)) {
return $this->mixManifest()->get($assetPath);
}
return $assetPath;
}
/**
* Return the mix manifest collection.
*
* @return \Tightenco\Collect\Support\Collection
*/
protected function mixManifest(): Collection
{
return Collection::make(json_decode(file_get_contents(
$this->container->get('base_path') . '/mix-manifest.json'
), true));
}
}

View File

@@ -2,6 +2,7 @@
namespace App\ViewFunctions;
use DI\Container;
use PHLAK\Config\Config;
abstract class ViewFunction
@@ -9,6 +10,9 @@ abstract class ViewFunction
/** @var string The function name */
protected $name = '';
/** @var Container The application container */
protected $container;
/** @var Config App configuration component */
protected $config;
@@ -17,8 +21,9 @@ abstract class ViewFunction
*
* @param \PHLAK\Config\Config $config
*/
public function __construct(Config $config)
public function __construct(Container $container, Config $config)
{
$this->container = $container;
$this->config = $config;
}

14
package-lock.json generated
View File

@@ -1464,12 +1464,11 @@
}
},
"axios": {
"version": "0.19.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.0.tgz",
"integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==",
"version": "0.19.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.1.tgz",
"integrity": "sha512-Yl+7nfreYKaLRvAvjNPkvfjnQHJM1yLBY3zhqAwcJSwR/6ETkanUgylgtIvkvz0xJ+p/vZuNw8X7Hnb7Whsbpw==",
"requires": {
"follow-redirects": "1.5.10",
"is-buffer": "^2.0.2"
"follow-redirects": "1.5.10"
},
"dependencies": {
"debug": {
@@ -1488,11 +1487,6 @@
"debug": "=3.1.0"
}
},
"is-buffer": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz",
"integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A=="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",

View File

@@ -10,7 +10,7 @@
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"dependencies": {
"axios": "^0.19.0",
"axios": "^0.19.1",
"vue": "^2.6.11"
},
"devDependencies": {

View File

@@ -2,12 +2,14 @@ let mix = require('laravel-mix');
let tailwindcss = require('tailwindcss');
require('laravel-mix-purgecss');
mix.sass('app/resources/sass/app.scss', 'app/dist').options({
mix.setPublicPath(path.resolve('.'));
mix.sass('app/resources/sass/app.scss', 'app/dist/app.css').options({
processCssUrls: false,
postCss: [tailwindcss('tailwind.config.js')]
});
mix.js('app/resources/js/app.js', 'app/dist');
mix.js('app/resources/js/app.js', 'app/dist/app.js');
mix.copyDirectory(
'node_modules/@fortawesome/fontawesome-free/webfonts',
@@ -16,8 +18,11 @@ mix.copyDirectory(
mix.purgeCss({
extensions: ["html", "js", "php", "scss", "twig", "vue"],
globs: ["**/*.php", "**/*.scss", "**/*.twig"],
folders: ["src"],
whitelist: ["html", "body", "main", "fab", "far", "fas", "fal", "fad"],
folders: ["app"],
whitelist: ["html", "body", "main", "fab", "fad", "fal", "far", "fas"],
whitelistPatterns: [/^fa\-/]
});
if (mix.inProduction()) {
mix.version();
}