kkszymanowski/laravel-js-config

Publish Laravel configuration to JS
8,780
Install
composer require kkszymanowski/laravel-js-config
Latest Version:1.0.9
PHP:^7.1|8.*
Laravel:5 – 9
License:MIT
Last Updated:Oct 24, 2022
Links: GitHub  ·  Packagist
Maintainer: KKSzymanowski

Laravel-JS-Config

Easily publish your Laravel configuration to JavaScript.

Requirements
  • PHP 7.*
  • Laravel >= 5.2
Installation
composer require kkszymanowski/laravel-js-config

On Laravel < 5.5 add LaravelJsConfig\LaravelJsConfigServiceProvider::class to app/config.php.

On Laravel >= 5.5 the service provider should be automatically discovered.

Publish assets
php artisan vendor:publish
Configure

In config/js-config.php there are following configuration options.

Output

Path of the output file generated from the command. By default resources/assets/js/config.js

Pretty

If true, the command will format the JSON configuration using JSON_PRETTY_PRINT.

Keys

List of configuration keys to be published. Can be either a specific key(like app.env) or a group of keys(like auth.defaults)

Make sure you don't publish your application key or any passwords.

Run
php artisan config:js
Integration with Laravel Mix

To publish the configuration every time the Mix build starts follow these steps:

  1. Install webpack-shell-plugin:
    # NPM
    npm install webpack-shell-plugin --save-dev
    
    # Yarn
    yarn add webpack-shell-plugin 
    
  2. In your webpack.mix.js file require the plugin
    const WebpackShellPlugin = require('webpack-shell-plugin');
    
    and register it to run before each build
    mix.webpackConfig({
        plugins: [
            new WebpackShellPlugin({
                onBuildStart: ['php artisan config:js'],
            }),
        ],
    });
    

If you're using the watch option in Laravel Mix and you want to refresh the published configuration you can either restart the build or run php artisan config:js in another terminal.

Related Packages

laracasts/utilities

Transform your PHP to JavaScript

10,999,527 2,199
laravel-dev-common/union-config

Laravel dev config util

193 0
moon/utilities-javascript

Transform your PHP to JavaScript

180 1
javascript/put-vars

Transform your PHP to JavaScript

63 1
jani/laravel-db-config

laravel 读写数据库Config,基于Laravel5.1插件。

42 0

Version History

Version Released PHP Laravel License
1.0.9 ^7.1|8.* >=5.2.0 MIT
1.0.8 ^7.1|8.* ~5.2|6.*|7.*|8.* MIT
1.0.7 ^7.1 ~5.2|6.*|7.* MIT
1.0.6 ^7.1 ~5.2|6.* MIT
1.0.5 7.* ~5.2 MIT