Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
laravel-config-to-js
Advanced tools
Automatically export laravel config variables to javascript using annotation
This package provides a clean, easy maintainable and fast way to re-use your Laravel config files on the client side (javascript). It's built to be used in a Laravel project with Gulp, but you're free to find other uses for it.
This a very early version of the project and might have errors. If you report them here, I'll be happy to fix them.
Install the package via npm:
npm install laravel-config-to-js
var buildJsConfig = require('laravel-config-to-js');
buildJSConfig(options);
The following options and its default values are:
{
configDirPath: './config',
destFilePath: './resources/assets/js/variables.js',
namespace: 'Config',
}
The package will go through all the configuration files in your Laravel project seeking comment that contains the annotation @jsVariable
. If found, the contents of the following option will be transformed to javascript. Every option found in the same file will be grouped down in a object with the name of that file and each group in a namespace.
Laravel config folder:
project
│ ...
└───config
│ app.php
│ custom.php
app.php contents:
return [
/*
|--------------------------------------------------------------------------
| Application URL
|--------------------------------------------------------------------------
|
| This URL is used by the console to properly generate URLs when using
| the Artisan command line tool. You should set this to the root of
| your application so that it is used when running Artisan tasks.
|
| @jsVariable
*/
'url' => 'http://laravel.com',
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/
'timezone' => 'Europe/London',
/*
|--------------------------------------------------------------------------
| Application Locale Configuration
|--------------------------------------------------------------------------
|
| The application locale determines the default locale that will be used
| by the translation service provider. You are free to set this value
| to any of the locales which will be supported by the application.
|
*/
// @jsVariable
'locale' => 'en',
];
custom.php contents:
return [
'my_important_things' => [
'right_here' => [
/**
* @jsVariable
*/
'this_key' => 'I need this on client side',
'other_key' => 'This is private, shhhh',
],
],
];
Output:
var Config = {
"app": {
"url": "http://www.laravel.com",
"locale": "en"
},
"event": {
"my_important_things": {
"right_here": {
"this_key": "I need this on client side"
}
}
}
}
There are some options that can't be supported, for obvious reasons. If you try to get one of these options you will get a "not supported" as value. This is the list:
env('APP_DEBUG', false),
Illuminate\View\ViewServiceProvider::class,
Laravel Config To Javascript is open-sourced software licensed under the MIT license
FAQs
Automatically export laravel config variables to javascript using annotation
The npm package laravel-config-to-js receives a total of 0 weekly downloads. As such, laravel-config-to-js popularity was classified as not popular.
We found that laravel-config-to-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.