Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mix.minify() doesn't minify! #1295

Closed
andy-hammond opened this issue Oct 31, 2017 · 12 comments
Closed

mix.minify() doesn't minify! #1295

andy-hammond opened this issue Oct 31, 2017 · 12 comments

Comments

@andy-hammond
Copy link

andy-hammond commented Oct 31, 2017

  • 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'
    });
}
@JeffreyWay
Copy link
Collaborator

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

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

@the94air
Copy link

the94air commented Nov 5, 2017

I do have the same issue when using the stand alone version also using npm run production

@JeffreyWay
Copy link
Collaborator

@andy-hammond I tried this out myself, and can't reproduce. So without more information, I'm going to close this.

@kiwina
Copy link

kiwina commented Jan 7, 2018

same here it does create the min version but it dosn't actually minify the file

@the94air
Copy link

the94air commented Jan 7, 2018

I solved the issue by reinstalling the dependencies (deleting this node_modules folder and npm install). It happens because I installed the dependencies with Windows and I got them compiled with Ubuntu npm run production ending up with unminified files.

@joshuaajones
Copy link

Confirmed fix with a clean npm install and npm run prod on Windows

@nezaboravi
Copy link

nezaboravi commented Jan 19, 2018

yeah does not minify for me as well, actually it makes it bigger regarding to console output:
Here is the screenshot
https://cl.ly/3Z0V361q3z2q

Here is the output:
Asset Size Chunks Chunk Names
/assets/main/js/app.js 1.18 MB 0 [emitted] [big] /assets/main/js/app
/assets/main/js/vendor.js 226 kB 1 [emitted] /assets/main/js/vendor
/assets/main/js/manifest.js 1.42 kB 2 [emitted] /assets/main/js/manifest
/assets/main/css/app.css 318 kB 0 [emitted] [big] /assets/main/js/app
/assets/main/js/app.min.js 1.21 MB [emitted]
/assets/main/css/app.min.css 317 kB [emitted]

@rohitbhirud
Copy link

rohitbhirud commented Feb 16, 2018

minification isn't working even after deleting node_modules and npm install.
my fix was to install cross-env & then adding it to scripts before NODE_ENV.

@ivansammartino
Copy link

Me too, the following code creates both custom.css and custom.min.css but they have the same size (and none of them is minified)

mix.sass('resources/assets/back/custom/sass/custom.scss', 'public/assets/back/custom.css')
    .minify('public/assets/back/custom.css');

If it can help, it happens on Windows 10 (Laragon as development environment)

@uzwebline
Copy link

Once again, the minification will only take place during a production build. (export NODE_ENV=production).

@MFFoX
Copy link

MFFoX commented 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"
  }

@the94air
Copy link

the94air commented Sep 2, 2018

Thanks, @MFFoX. I was missing the cross-env package on all of my scripts. I can confirm that your solution is 💯working. A lot of Laravel-mix is not minifying issues in this repo might be related to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants