babel-plugin-laravel-facades
v0.0.3
Published
Generates array of used translation/configuration strings for laravel-localization and laravel-config libraries
Downloads
4
Readme
babel-plugin-laravel-facades
Babel plugin that detects usages of the modules laravel-localization and laravel-config, and generates a JSON file containing the used keys.
This JSON file can be used to generate the data to be sent to the browser, using andywer module, or any other similar solution.
Installation
npm install babel-plugin-laravel-facades
Usage
In the example below, there is a an app.js file, which uses the laravel-localization and laravel-config modules for logging some stuff in the console. The app could be written in separated modules as well. The build file is just using browserify with babelify to build the app.js. It could also be used inside a gulp build.
After running the script build.js, the file facades-data.json is generated.
app.js:
import Lang from 'laravel-localization'; import Config from 'laravel-config'; Lang.addMessages({ 'en': { 'message key': 'translated message' } }); Lang.setLocale('en'); Config.addConfig({ 'config key': 'config value' }); console.log(Lang.get('message key')); // translated message console.log(Config.get('config key')); // config value;
build.js:
const browserify = require('browserify'); const babelify = require('babelify'); const laravelJsFacades = require('babel-plugin-laravel-facades'); const laravelJsFacadesInstance = laravelJsFacades.instance(); browserify('app.js') .transform(babelify, { presets: ['es2015'], plugins: [ [ 'laravel-facades', laravelJsFacadesInstance ] ] }) .bundle() .on('end', () => laravelJsFacadesInstance.write('facades-data.json')) .pipe(process.stdout);
generated facades-data.json after running build.js:
{"messages":["message key"],"configs":["config key"]}