vuejs / laravel-elixir-vue-2

Laravel Elixir Vue 2.0 support plugin
105 stars 20 forks source link

Question: production ready Vue source #3

Closed kfirba closed 6 years ago

kfirba commented 7 years ago

Hey.

Probably a stupid question, but I will ask it anyways:

Is this plugin configuring elixir and telling it to compile Vue and strip any warning (perhaps also translate templates to render functions) when elixir is running with the production flag?

zackkrida commented 7 years ago

I'd be curious as well to learn more about production environment configuration. I imagine we'd need to add some config to vue-loader (https://github.com/vuejs/laravel-elixir-vue-2/blob/master/index.js#L21)?

andredewaard commented 7 years ago

gulp --production is also for me not creating real production files. Vue-devtools are still available and all warnings works as well.

damiencriado commented 7 years ago

No idea how to fix that?

evertramos commented 7 years ago

A workaroud would be:

// Comment these three for local build.
Vue.config.devtools = false
Vue.config.debug = false
Vue.config.silent = true

As of here.

ZhihaoLau commented 7 years ago

You can do this, tho.

createwebpack.config.js in project root

var webpack = require('webpack')

module.exports = {
  plugins: [
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': '"production"'
    })
  ]
}

In case you don't know: laravel-elixir will merge your self-defined webpack.config.js into itself.

in your code:

Vue.config.devtools = process.env.NODE_ENV !== 'production'
Vue.config.debug = process.env.NODE_ENV !== 'production'
Vue.config.silent = process.env.NODE_ENV === 'production'

Whenever you try to switch to development/production mode, just re-set the value in webpack.DefinePlugin

florentb commented 7 years ago

Depending on your setup, you can create a webpack.config.js file as @ZhihaoLau wrote but instead of setting your staging directly you could use the "real" NODE_ENV env var like this:

var webpack = require('webpack')

module.exports = {
    plugins: [
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
        })
    ]
}

This way, you do something like this:

export NODE_ENV=production && gulp --production