From acd26c85f63e716205c6536beeb334b6775c14f3 Mon Sep 17 00:00:00 2001 From: Gertjan Krol Date: Sat, 20 Aug 2022 23:12:10 +0200 Subject: [PATCH] Added vite for JS/CSS assets, made some changes to ServiceProvider --- .gitignore | 2 + composer.json | 3 +- package.json | 10 +++++ .../pkg-name.css => public/app.923f0842.css | 0 .../js/pkg-name.js => public/app.cdb7ca6c.js | 0 public/manifest.json | 12 ++++++ resources/js/app.js | 1 + resources/sass/app.scss | 1 + src/Skeleton.php | 5 ++- src/SkeletonFacade.php | 6 +-- src/SkeletonServiceProvider.php | 39 +++++++++---------- vite.config.js | 20 ++++++++++ webpack.mix.js | 15 +++++++ 13 files changed, 87 insertions(+), 27 deletions(-) create mode 100644 package.json rename resources/assets/css/pkg-name.css => public/app.923f0842.css (100%) rename resources/assets/js/pkg-name.js => public/app.cdb7ca6c.js (100%) create mode 100644 public/manifest.json create mode 100644 resources/js/app.js create mode 100644 resources/sass/app.scss create mode 100644 vite.config.js create mode 100644 webpack.mix.js diff --git a/.gitignore b/.gitignore index 9c00e42..403dc62 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ /.idea/ +/node_modules/ /vendor/ composer.lock +package-lock.json *cache* *.log *.tmp diff --git a/composer.json b/composer.json index e754f0f..c748f1a 100644 --- a/composer.json +++ b/composer.json @@ -16,10 +16,9 @@ ], "require": { "php": "^8.1", - "illuminate/support": "^8.0" + "illuminate/support": "^9.25" }, "require-dev": { - "orchestra/testbench": "^6.24", "enlightn/security-checker": "^1.10", "crawl/coding-standard": "^1.0", "mockery/mockery": "^1.5", diff --git a/package.json b/package.json new file mode 100644 index 0000000..4d59169 --- /dev/null +++ b/package.json @@ -0,0 +1,10 @@ +{ + "private": true, + "scripts": { + "build": "vite build" + }, + "devDependencies": { + "laravel-vite-plugin": "^0.5", + "vite": "^3.0" + } +} diff --git a/resources/assets/css/pkg-name.css b/public/app.923f0842.css similarity index 100% rename from resources/assets/css/pkg-name.css rename to public/app.923f0842.css diff --git a/resources/assets/js/pkg-name.js b/public/app.cdb7ca6c.js similarity index 100% rename from resources/assets/js/pkg-name.js rename to public/app.cdb7ca6c.js diff --git a/public/manifest.json b/public/manifest.json new file mode 100644 index 0000000..825f3e3 --- /dev/null +++ b/public/manifest.json @@ -0,0 +1,12 @@ +{ + "resources/js/app.js": { + "file": "app.cdb7ca6c.js", + "src": "resources/js/app.js", + "isEntry": true + }, + "resources/sass/app.scss": { + "file": "app.923f0842.css", + "src": "resources/sass/app.scss", + "isEntry": true + } +} \ No newline at end of file diff --git a/resources/js/app.js b/resources/js/app.js new file mode 100644 index 0000000..33f2668 --- /dev/null +++ b/resources/js/app.js @@ -0,0 +1 @@ +/** Package JS goes here */ diff --git a/resources/sass/app.scss b/resources/sass/app.scss new file mode 100644 index 0000000..1f86393 --- /dev/null +++ b/resources/sass/app.scss @@ -0,0 +1 @@ +/** Package CSS goes here */ diff --git a/src/Skeleton.php b/src/Skeleton.php index dc82b38..f816ca7 100644 --- a/src/Skeleton.php +++ b/src/Skeleton.php @@ -4,7 +4,10 @@ declare(strict_types=1); namespace Crawl\Skeleton; -class Skeleton +final class Skeleton { + public const PACKAGE_VENDOR = 'crawl'; + public const PACKAGE_NAME = 'skeleton'; + // Build your next great package. } diff --git a/src/SkeletonFacade.php b/src/SkeletonFacade.php index 85e604e..077605c 100644 --- a/src/SkeletonFacade.php +++ b/src/SkeletonFacade.php @@ -7,15 +7,15 @@ namespace Crawl\Skeleton; use Illuminate\Support\Facades\Facade; /** - * @see \Crawl\Skeleton\Skeleton + * @see Skeleton */ -class SkeletonFacade extends Facade +final class SkeletonFacade extends Facade { /** * Get the registered name of the component. */ protected static function getFacadeAccessor(): string { - return SkeletonServiceProvider::PACKAGE_NAME; + return Skeleton::PACKAGE_NAME; } } diff --git a/src/SkeletonServiceProvider.php b/src/SkeletonServiceProvider.php index ea1a34f..6dcb0a4 100644 --- a/src/SkeletonServiceProvider.php +++ b/src/SkeletonServiceProvider.php @@ -6,11 +6,8 @@ namespace Crawl\Skeleton; use Illuminate\Support\ServiceProvider; -class SkeletonServiceProvider extends ServiceProvider +final class SkeletonServiceProvider extends ServiceProvider { - public const PACKAGE_VENDOR = 'crawl'; - public const PACKAGE_NAME = 'skeleton'; - private const COMMANDS = [ ]; @@ -21,31 +18,31 @@ class SkeletonServiceProvider extends ServiceProvider public function boot(): void { // Optional methods to load package assets - //$this->loadMigrationsFrom($this->getPackagePath() . '/database/migrations'); - //$this->loadRoutesFrom($this->getPackagePath() . '/routes.php'); - //$this->loadTranslationsFrom($this->getPackagePath() . '/resources/lang', self::PACKAGE_NAME); - //$this->loadViewsFrom($this->getPackagePath() . '/resources/views', self::PACKAGE_NAME); + //$this->loadMigrationsFrom($this->packageRoot() . '/database/migrations'); + //$this->loadRoutesFrom($this->packageRoot() . '/routes.php'); + //$this->loadTranslationsFrom($this->packageRoot() . '/resources/lang', Skeleton::PACKAGE_NAME); + //$this->loadViewsFrom($this->packageRoot() . '/resources/views', Skeleton::PACKAGE_NAME); if ($this->app->runningInConsole()) { // Publish config $this->publishes([ - $this->getPackagePath() . '/config/config.php' => config_path(self::PACKAGE_NAME . '.php'), - ], 'config'); + $this->packageRoot() . '/config/config.php' => config_path(Skeleton::PACKAGE_NAME . '.php'), + ], Skeleton::PACKAGE_NAME . '-config'); // Publish assets //$this->publishes([ - // $this->getPackagePath() . '/resources/assets' => public_path('vendor/' . self::PACKAGE_NAME), - //], ['assets', 'public']); + // $this->packageRoot() . '/public' => public_path('vendor/' . Skeleton::PACKAGE_NAME), + //], Skeleton::PACKAGE_NAME . '-assets'); - // Publishing translation files + // Publish translation files //$this->publishes([ - // $this->getPackagePath() . '/resources/lang' => resource_path('lang/vendor/' . self::PACKAGE_NAME), - //], 'lang'); + // $this->packageRoot() . '/resources/lang' => resource_path('lang/vendor/' . Skeleton::PACKAGE_NAME), + //], Skeleton::PACKAGE_NAME . '-lang'); - // Publishing views + // Publish views //$this->publishes([ - // $this->getPackagePath() . '/resources/views' => resource_path('views/vendor/' . self::PACKAGE_NAME), - //], 'views'); + // $this->packageRoot() . '/resources/views' => resource_path('views/vendor/' . Skeleton::PACKAGE_NAME), + //], Skeleton::PACKAGE_NAME . '-views'); // Registering package commands $this->commands(self::COMMANDS); @@ -58,15 +55,15 @@ class SkeletonServiceProvider extends ServiceProvider public function register(): void { // Automatically apply the package configuration - $this->mergeConfigFrom($this->getPackagePath() . '/config/config.php', self::PACKAGE_NAME); + $this->mergeConfigFrom($this->packageRoot() . '/config/config.php', Skeleton::PACKAGE_NAME); // Register the main class to use with the facade - $this->app->singleton(self::PACKAGE_NAME, static function () { + $this->app->singleton(Skeleton::PACKAGE_NAME, static function () { return new Skeleton(); }); } - private function getPackagePath(): string + private function packageRoot(): string { return realpath(__DIR__ . '/..'); } diff --git a/vite.config.js b/vite.config.js new file mode 100644 index 0000000..2d7f605 --- /dev/null +++ b/vite.config.js @@ -0,0 +1,20 @@ +import { defineConfig } from 'vite'; +import laravel from 'laravel-vite-plugin'; + +export default defineConfig({ + build: { + outDir: 'public', + assetsDir: '', + }, + plugins: [ + laravel({ + input: [ + 'resources/sass/app.scss', + 'resources/js/app.js', + ], + refresh: false, + publicDirectory: 'public', + buildDirectory: '.', + }), + ], +}); \ No newline at end of file diff --git a/webpack.mix.js b/webpack.mix.js new file mode 100644 index 0000000..0d1f77e --- /dev/null +++ b/webpack.mix.js @@ -0,0 +1,15 @@ +const mix = require('laravel-mix'); +mix.options({ + terser: { + terserOptions: { + compress: { + drop_console: true, + }, + }, + }, +}); +mix.setPublicPath('public') + +mix.js('resources/js/app.js', '') +mix.sass('resources/sass/app.scss', '') +mix.version()