Added vite for JS/CSS assets, made some changes to ServiceProvider

master
Gertjan Krol 2022-08-20 23:12:10 +02:00
parent 972ddb9214
commit acd26c85f6
13 changed files with 87 additions and 27 deletions

2
.gitignore vendored
View File

@ -1,6 +1,8 @@
/.idea/ /.idea/
/node_modules/
/vendor/ /vendor/
composer.lock composer.lock
package-lock.json
*cache* *cache*
*.log *.log
*.tmp *.tmp

View File

@ -16,10 +16,9 @@
], ],
"require": { "require": {
"php": "^8.1", "php": "^8.1",
"illuminate/support": "^8.0" "illuminate/support": "^9.25"
}, },
"require-dev": { "require-dev": {
"orchestra/testbench": "^6.24",
"enlightn/security-checker": "^1.10", "enlightn/security-checker": "^1.10",
"crawl/coding-standard": "^1.0", "crawl/coding-standard": "^1.0",
"mockery/mockery": "^1.5", "mockery/mockery": "^1.5",

10
package.json Normal file
View File

@ -0,0 +1,10 @@
{
"private": true,
"scripts": {
"build": "vite build"
},
"devDependencies": {
"laravel-vite-plugin": "^0.5",
"vite": "^3.0"
}
}

12
public/manifest.json Normal file
View File

@ -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
}
}

1
resources/js/app.js Normal file
View File

@ -0,0 +1 @@
/** Package JS goes here */

1
resources/sass/app.scss Normal file
View File

@ -0,0 +1 @@
/** Package CSS goes here */

View File

@ -4,7 +4,10 @@ declare(strict_types=1);
namespace Crawl\Skeleton; namespace Crawl\Skeleton;
class Skeleton final class Skeleton
{ {
public const PACKAGE_VENDOR = 'crawl';
public const PACKAGE_NAME = 'skeleton';
// Build your next great package. // Build your next great package.
} }

View File

@ -7,15 +7,15 @@ namespace Crawl\Skeleton;
use Illuminate\Support\Facades\Facade; 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. * Get the registered name of the component.
*/ */
protected static function getFacadeAccessor(): string protected static function getFacadeAccessor(): string
{ {
return SkeletonServiceProvider::PACKAGE_NAME; return Skeleton::PACKAGE_NAME;
} }
} }

View File

@ -6,11 +6,8 @@ namespace Crawl\Skeleton;
use Illuminate\Support\ServiceProvider; 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 = [ private const COMMANDS = [
]; ];
@ -21,31 +18,31 @@ class SkeletonServiceProvider extends ServiceProvider
public function boot(): void public function boot(): void
{ {
// Optional methods to load package assets // Optional methods to load package assets
//$this->loadMigrationsFrom($this->getPackagePath() . '/database/migrations'); //$this->loadMigrationsFrom($this->packageRoot() . '/database/migrations');
//$this->loadRoutesFrom($this->getPackagePath() . '/routes.php'); //$this->loadRoutesFrom($this->packageRoot() . '/routes.php');
//$this->loadTranslationsFrom($this->getPackagePath() . '/resources/lang', self::PACKAGE_NAME); //$this->loadTranslationsFrom($this->packageRoot() . '/resources/lang', Skeleton::PACKAGE_NAME);
//$this->loadViewsFrom($this->getPackagePath() . '/resources/views', self::PACKAGE_NAME); //$this->loadViewsFrom($this->packageRoot() . '/resources/views', Skeleton::PACKAGE_NAME);
if ($this->app->runningInConsole()) { if ($this->app->runningInConsole()) {
// Publish config // Publish config
$this->publishes([ $this->publishes([
$this->getPackagePath() . '/config/config.php' => config_path(self::PACKAGE_NAME . '.php'), $this->packageRoot() . '/config/config.php' => config_path(Skeleton::PACKAGE_NAME . '.php'),
], 'config'); ], Skeleton::PACKAGE_NAME . '-config');
// Publish assets // Publish assets
//$this->publishes([ //$this->publishes([
// $this->getPackagePath() . '/resources/assets' => public_path('vendor/' . self::PACKAGE_NAME), // $this->packageRoot() . '/public' => public_path('vendor/' . Skeleton::PACKAGE_NAME),
//], ['assets', 'public']); //], Skeleton::PACKAGE_NAME . '-assets');
// Publishing translation files // Publish translation files
//$this->publishes([ //$this->publishes([
// $this->getPackagePath() . '/resources/lang' => resource_path('lang/vendor/' . self::PACKAGE_NAME), // $this->packageRoot() . '/resources/lang' => resource_path('lang/vendor/' . Skeleton::PACKAGE_NAME),
//], 'lang'); //], Skeleton::PACKAGE_NAME . '-lang');
// Publishing views // Publish views
//$this->publishes([ //$this->publishes([
// $this->getPackagePath() . '/resources/views' => resource_path('views/vendor/' . self::PACKAGE_NAME), // $this->packageRoot() . '/resources/views' => resource_path('views/vendor/' . Skeleton::PACKAGE_NAME),
//], 'views'); //], Skeleton::PACKAGE_NAME . '-views');
// Registering package commands // Registering package commands
$this->commands(self::COMMANDS); $this->commands(self::COMMANDS);
@ -58,15 +55,15 @@ class SkeletonServiceProvider extends ServiceProvider
public function register(): void public function register(): void
{ {
// Automatically apply the package configuration // 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 // 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(); return new Skeleton();
}); });
} }
private function getPackagePath(): string private function packageRoot(): string
{ {
return realpath(__DIR__ . '/..'); return realpath(__DIR__ . '/..');
} }

20
vite.config.js Normal file
View File

@ -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: '.',
}),
],
});

15
webpack.mix.js Normal file
View File

@ -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()