Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

obfuscate code with laravel mix

I have a web app with laravel and vuejs. I use laravel-mix and in my webpack.mix.js i have:

const { mix } = require('laravel-mix');
mix.sourceMaps();
mix.js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css');

now I would obfuscate code, so all my components, how can I do this with laravel-mix?

like image 905
LorenzoBerti Avatar asked Jul 28 '26 03:07

LorenzoBerti


2 Answers

npm run dev will NOT uglify / minify your code, but npm run production WILL.

If you are looking to use uglify...

laravel mix is just a wrapper around webpack. So you can install the UglifyWepackPlugin here https://webpack.js.org/plugins/uglifyjs-webpack-plugin/

Afterwards, you can edit your mix.webpackConfig to use the plugin, as detailed here: https://laravel.com/docs/5.5/mix#custom-webpack-configuration

like image 118
Brian Glaz Avatar answered Jul 31 '26 17:07

Brian Glaz


Install https://github.com/javascript-obfuscator/javascript-obfuscator and https://github.com/javascript-obfuscator/webpack-obfuscator. After that you need to include de plugin in the webpack configuration, you can do that adding the next code in webpack.mix.js file.

let mix = require('laravel-mix');
let JavaScriptObfuscator = require('webpack-obfuscator');

mix.webpackConfig({
    plugins: [
        new JavaScriptObfuscator ({
            rotateUnicodeArray: true
        }, ['excluded_bundle_name.js'])
    ],
});

mix.js('resources/assets/js/app.js', 'public/js');

After that all your js files will be obfuscater.

like image 34
Isaac Rodriguez Avatar answered Jul 31 '26 17:07

Isaac Rodriguez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!