Search code examples
javascriptminify

Cannot call function after minification


I am developing a web application in Laravel. Primarily, I had kept my js codes in public directory and everything was working. But later, I had planned to move them to the resources directory and minify them.

Now, the problem is the functionalities, those are getting triggered by the JQuery are running well. But the functions, I am calling from the blade template are getting failed as the js is minified.

Here, I need some solution without moving my JS codes to the public directory.

I had run NPM to minify the JS.

npm run prod

After this, the code is failing to call a function.

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css');

mix.js('resources/js/validation.js', 'public/js');

Solution

  • Actually, I found the answer.

    npm run prod actually references all method and variable declaration and calling functions with minimum characters to minify and optimize them.

    When I am calling one function from HTML, that function calling name is not compiled in HTML, but changed in JS file, turning out to be not found.

    I have moved my function call with DOM events to JS files to make them in the same stream