Vue-cli: Build for production not minifying app.js

Created on 17 Aug 2018  路  6Comments  路  Source: vuejs/vue-cli

Version

3.0.1

Node and OS info

Node 10.6.0 / npm 6.4.0 / Windows 10

Steps to reproduce

  • Created a new project with vue create and chose my settings
  • Added some SCSS, imported, and ran npm run build

What is expected?

Split CSS from JS, and minify everything.

What is actually happening?

CSS is still inside JS and not only the JS file app.js is not being minified, but all evals from development are still in there.


I've restarted my computer, deleted node_modules and reinstalled everything. Also I notice the "building for production" text is displayed, so it should be doing the right thing, yet the output app.js file is 933.61kb in size, and I only have a simple Vue Vuex setup and some CSS, nothing more.

Most helpful comment

@rowild as it turns out, @yyx990803 was right. However, on Windows, I have no idea where that would be set. That said, I added cross-env and changed my build script to:

cross-env NODE_ENV=production vue-cli-service build

It solved my problem.

All 6 comments

You probably have a default NODE_ENV set in your shell. Delete it, or explicitly set NODE_ENV when running build.

Is it possible to check if there is a "default NODE_ENV" value set anywhere?

@rowild as it turns out, @yyx990803 was right. However, on Windows, I have no idea where that would be set. That said, I added cross-env and changed my build script to:

cross-env NODE_ENV=production vue-cli-service build

It solved my problem.

Yes, Chen's tip is totally correct.
I was just wondering, if there is some kind of magic terminal command that spits out, whether I have NODE_ENV defined anywhere globally... :-)
Thank you for your feedback!!!

You can try echoing your environment vars directly from the console/terminal/prompt.

This anser and the answer below it covers the main ways of doing that.

For, Windows user, this is what worked for me:

Check NODE_ENV in the text file:
printenv > env.txt && notepad env.txt

(set NODE_ENV to production if it is something else)

OR try cross-env:

npm i -D cross-env

...then in the package.json

cross-env set NODE_ENV=production vue-cli-service build

My 850KB file sized down to around 82KB file

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jgribonvald picture jgribonvald  路  3Comments

chasegiunta picture chasegiunta  路  3Comments

PrimozRome picture PrimozRome  路  3Comments

Gonzalo2683 picture Gonzalo2683  路  3Comments

csakis picture csakis  路  3Comments