question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mix.minify() doesn't minify!

See original GitHub issue
  • Laravel Mix Version: 1.5.1 (npm list --depth=0)
  • Node Version (node -v): 6.11.2
  • NPM Version (npm -v): 3.10.10
  • OS: Windows 10

I just get an index.min.js file that is slightly larger than the ‘unminified’ one.

const {mix} = require('laravel-mix');

mix.js('resources/assets/js/index.js', 'public/js')
    .sass('resources/assets/scss/styles.scss','public/css', {
        outputStyle: 'compressed'
    })
      
if(process.env.NODE_ENV.trim() === 'production'){
    mix.minify('public/js/index.js')
    mix.version();
} else {
    mix.browserSync({
        proxy: 'http://localhost:8000'
    });
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12

github_iconTop GitHub Comments

12reactions
MFFoXcommented, Aug 22, 2018

Adding to what @rohitbhirud and others have said, my problem was with the NODE_ENV not being set properly because of the scripts not being platform independent. I fixed this by using the cross-env package ie within your package.json scripts:

"scripts": {
    "development": "cross-env NODE_ENV=development webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
    "production": "cross-env NODE_ENV=production webpack --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
  }

6reactions
JeffreyWaycommented, Oct 31, 2017

First, you don’t need to do that check for production mode.

Minification will only take place during production builds (npm run production).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Concatenation and Minification | Laravel Mix Documentation
If used properly, Laravel Mix and webpack should take care of all the ... Similarly, you may also minify one or more files...
Read more >
How does minification of css files using laravel mix work?
When running npm run dev , both files are of the same size and it is 160 kB , i.e. both are non-minified....
Read more >
Laravel mix minify but copy un-minified version - Laracasts
Laravel mix minify but copy un-minified version. HI, What I am trying to achieve is minifying a js file and copy the result...
Read more >
Compiling Assets (Mix) - The PHP Framework For Web Artisans
Mix provides several features to help you work with your JavaScript files, such as compiling modern ECMAScript, module bundling, minification, and concatenating ...
Read more >
laravel-mix-views-minifier - npm
Minify template files with Laravel Mix. Latest version: 2.0.1, last published: 2 years ago. Start using laravel-mix-views-minifier in your ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found