{"id":13805106,"url":"https://github.com/cbl/blade-script","last_synced_at":"2025-09-04T01:37:01.178Z","repository":{"id":62500235,"uuid":"274643424","full_name":"cbl/blade-script","owner":"cbl","description":"A package to easily add transpiled \u0026 minified scripts to your blade components.","archived":false,"fork":false,"pushed_at":"2024-05-13T09:16:43.000Z","size":35,"stargazers_count":48,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-31T04:28:12.059Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cbl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-24T10:41:52.000Z","updated_at":"2024-05-17T16:38:17.000Z","dependencies_parsed_at":"2024-06-19T11:14:06.967Z","dependency_job_id":null,"html_url":"https://github.com/cbl/blade-script","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/cbl/blade-script","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbl%2Fblade-script","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbl%2Fblade-script/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbl%2Fblade-script/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbl%2Fblade-script/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cbl","download_url":"https://codeload.github.com/cbl/blade-script/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cbl%2Fblade-script/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273539293,"owners_count":25123499,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-03T02:00:09.631Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T01:00:57.600Z","updated_at":"2025-09-04T01:37:01.150Z","avatar_url":"https://github.com/cbl.png","language":"PHP","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"# Blade Script\n\nA package to easily add transpiled \u0026 minified scripts to your blade components.\n\n```php\n\u003cbutton class=\"btn\" onlick=\"myFunction()\"\u003e{{ $slot }}\u003c/button\u003e\n\n\u003cx-script\u003e\nfunction myFunction() {\n    // Do something.\n}\n\u003c/x-script\u003e\n```\n\n## Introduction\n\nIn case you want to add javascript functionality to a blade component, you can\nwrite it directly in the script tag. However, the script will then not be\nminified and if a component is used multiple times, the script tag will also be\nincluded multiple times.\n\nBlade Script solves these problems. The javascript code can be minified in\nproduction and each script tag is only included once all without running a\ncompiler separately. Also only required scripts are included.\n\nAdditionally there is the possibility to add transpilers like\n[babel](https://babeljs.io/).\n\n## Installation\n\nThe package can be easily installed via composer.\n\n```shell\ncomposer require cbl/blade-script\n```\n\nNow the necessary assets must be published. This includes the script.php config\nand the storage folder where the compiled scripts are stored.\n\n```shell\nphp artisan vendor:publish --provider=\"BladeScript\\ServiceProvider\"\n```\n\n## Include Scripts\n\nThe blade component `x-scripts` includes all required scripts, so it may be\nplaced at the very bottom of your **body**.\n\n```php\n\u003cbody\u003e\n    ...\n\n    \u003cx-scripts /\u003e\n\u003c/body\u003e\n```\n\n## Usage\n\nEach blade component can contain exactly one `x-script` component. Your scripts\ncan then be written inside the wrapper like so.\n\n```php\n\u003cbutton class=\"btn\" onlick=\"myFunction()\"\u003e{{ $slot }}\u003c/button\u003e\n\n\u003cx-script\u003e\nmyFunction() {\n    // Do something.\n}\n\u003c/x-script\u003e\n```\n\n## Optimizing Scripts\n\nBlade scripts share the same behavior as Views. As suggested in the\n[View documentation](https://laravel.com/docs/7.x/views#optimizing-views), the\n`script:cache` command can be added to your deployment workflow to ensure that\nall scripts are compiled and thus improve performance.\n\n```shell\nphp artisan script:cache\n```\n\nYou may use the `script:clear` command to clear the script cache:\n\n```shell\nphp artisan script:clear\n```\n\n## Write Transpiler\n\nYou can easily add transpilers to the compiler, the following example explains\nhow to create and include a transpiler.\n\nFirst you have to create a transpiler class that implements the\n`BladeScript\\Contracts\\Transpiler` contract.\n\n```php\n\nnamespace BladeBabel;\n\nuse Babel\\Transpiler as Babel;\nuse BladeScript\\Contracts\\Transpiler;\n\nclass BabelTranspiler implements Transpiler\n{\n    public function transpile($script)\n    {\n        return Babel::transform($script);\n    }\n}\n```\n\nThe transpiler can now be added to the compiler in your service provider like\nso:\n\n```php\n\nnamespace BladeBabel;\n\nuse Illuminate\\Support\\ServiceProvider;\n\nclass BabelServiceProvider extends ServiceProvider\n{\n    public function register()\n    {\n        $this-\u003eapp-\u003eafterResolving('script.compiler', function ($compiler) {\n            $compiler-\u003eaddTranspiler(new BabelTranspiler);\n        });\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcbl%2Fblade-script","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcbl%2Fblade-script","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcbl%2Fblade-script/lists"}