{"id":14981855,"url":"https://github.com/flat3/babel-blade","last_synced_at":"2025-10-29T09:30:18.976Z","repository":{"id":62505391,"uuid":"336519506","full_name":"flat3/babel-blade","owner":"flat3","description":"Blade compiler for inline Babel scripts","archived":false,"fork":false,"pushed_at":"2021-02-07T19:01:25.000Z","size":55,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T00:31:46.473Z","etag":null,"topics":["babel","babeljs","blade","laravel"],"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/flat3.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-06T11:15:42.000Z","updated_at":"2023-06-21T13:36:44.000Z","dependencies_parsed_at":"2022-11-02T12:16:47.466Z","dependency_job_id":null,"html_url":"https://github.com/flat3/babel-blade","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flat3%2Fbabel-blade","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flat3%2Fbabel-blade/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flat3%2Fbabel-blade/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flat3%2Fbabel-blade/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flat3","download_url":"https://codeload.github.com/flat3/babel-blade/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238795478,"owners_count":19531753,"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","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":["babel","babeljs","blade","laravel"],"created_at":"2024-09-24T14:04:23.692Z","updated_at":"2025-10-29T09:30:18.553Z","avatar_url":"https://github.com/flat3.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Babel compiler for Laravel Blade\n\nThis package allows you to safely write modern, inline JavaScript in blade templates.\nCompilation only happens at Blade template caching time, so has no effect on production performance.\n\n## Installation\n\nTo install the package via composer:\n\n`composer require flat3/babel-blade`\n\nThe compiler expects a nodejs install on the same PATH that is being used by your PHP interpreter.\n\nYou must install babel (and normally the env preset) in your Laravel project:\n\n`npm install --dev @babel/core @babel/preset-env`\n\nThe compiler looks for a babel configuration starting from the view root (normally resources/views) and searching upwards.\nYou can therefore use any existing babel configuration file in your project, or you can create one in resources/views that will only be used for babel-blade.\n\nFor example at `resources/views/.babelrc.json`\n\n```\n{\n  \"presets\": [\n    [\n      \"@babel/preset-env\",\n      {\n        \"targets\": {\n          \"chrome\": \"58\",\n          \"ie\": \"11\"\n        }\n      }\n    ]\n  ]\n}\n```\n\n## Usage\n\nBabel-blade looks for script blocks that use the string literal `\u003cscript type=\"text/babel\"\u003e` so no other javascript or script block will be modified.\n\nThis script block using the babel config above:\n```\n\u003cscript type=\"text/babel\"\u003e\n(...args) =\u003e console.log(...args)\n\u003c/script\u003e\n```\nwill be transformed at compile time into:\n```\n\u003cscript type=\"text/javascript\"\u003e\n(function() { \"use strict\";\n\n(function () {\n  var _console;\n\n  return (_console = console).log.apply(_console, arguments);\n});\n  \n})();\n\u003c/script\u003e\n```\n\n## Laravel Vapor\n\nThe Vapor build process clears the view caches and builds templates on first load server-side.\nThis is incompatible with babel-blade, since nodejs etc. will not be available.\n\nTo work around this, invoke the build as part of the vapor deploy process as `BABEL_BLADE_CACHE=1 php artisan view:cache`.\nThis will compile the templates locally into blade files in the view root, and add `@include`s to pull the compiled code\nin during compilation.\n\n## Polyfills\n\nBabel implements async/await using generators, which need to be polyfilled on older platforms.\nWithout the polyfill you'll see the error:\n```\nReferenceError: Can't find variable: regeneratorRuntime\n```\nTo solve this you can include an additional script tag that includes the polyfill, for example:\n```\n\u003cscript src=\"https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.12.1/polyfill.min.js\"\u003e\u003c/script\u003e\n```\n\n## Blade directives\n\nBecause babel-blade runs early in the compilation process, directives such as `@json($src)` haven't been parsed yet and will be passed to Babel as they are.\n\nYou will then get failures such as ```Support for the experimental syntax 'decorators-legacy' isn't currently enabled``` as Babel tries to parse `@json`.\n\nThere is likely not a solution to this due to the order of execution in blade, instead use the style `\"{{$src}}\" with appropriate escaping.`\n\n## License\n\nCopyright © Chris Lloyd\n\nFlat3 babel-blade is open-sourced software licensed under the [MIT license]","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflat3%2Fbabel-blade","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflat3%2Fbabel-blade","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflat3%2Fbabel-blade/lists"}