Search code examples
laravelminifylaravel-mix

minify js and styles in laravel 5


How can I minify my JavaScript and css files all in one?

currently I have:

let mix = require('laravel-mix');

mix.styles([
  'theme/admin/assets/css/bootstrap.css',
  'theme/admin/assets/font-awesome/css/font-awesome.css',
  'theme/admin/assets/css/zabuto_calendar.css',
  'theme/admin/assets/lineicons/style.css',
  'theme/admin/assets/css/style.css',
  'theme/admin/assets/css/style-responsive.css',
  'css/adminstyle.css'
], 'public/css/admin.css');

mix.scripts([
  'theme/admin/assets/js/jquery.min.js',
  'theme/admin/assets/js/bootstrap.min.js',
  'theme/admin/assets/js/jquery.dcjqaccordion.2.7.js',
  'theme/admin/assets/js/jquery.scrollTo.min.js',
  'theme/admin/assets/js/jquery.nicescroll.js',
  'theme/admin/assets/js/jquery.sparkline.js',
  'theme/admin/assets/js/common-scripts.js',
  'theme/admin/assets/js/zabuto_calendar.js'
], 'public/js/admin.js');

in my webpack.mix.js file but it creates empty files.


Solution

  • You have to use full path starting from the root directory of your Laravel application.

    So instead of:

    'theme/admin/assets/css/bootstrap.css'
    

    As you've said that theme is under public, you should do this:

    'public/theme/admin/assets/css/bootstrap.css'
    

    Do this update on the rest of your URLs