I've got an existing code base in which Vue.js has performance problems. I also see this notice in the browser console:
so I guess an easy fix could be to put Vue into production mode.
In the suggested link I try to follow the instructions for webpack. We're on Webpack version 2.7 (current stable version is 4.20). In the instructions it says that in Webpack 3 and earlier, you’ll need to use DefinePlugin
:
var webpack = require('webpack')
module.exports = {
// ...
plugins: [
// ...
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
]
}
So in my package.json I've got a build script defined:
To build for production I run yarn run build
and it runs a build.js
file (paste here) which in turn calls webpack.base.conf.js
(paste here) and webpack.prod.conf.js
(paste here).
As you can see in the paste I use the DefinePlugin
as suggested by the docs.
I also found a file called vue-loader.conf.js
(paste here) and to be sure I also added the DefinePlugin
in there as well.
I can run yarn run build
which ends without errors, but when serve the site over Apache and open the browser it still shows the notification that we're in development mode.
To be sure it actually uses the files created by webpack I completely removed the folder /public/webpack/
and checked that the webinterface didn't load correctly without the missing files and then built again to see if it loaded correctly after the command finished. So it does actually use the files built by this webpack process. But Vue is actually not created in production mode.
Does anybody know what I'm doing wrong here? All tips are welcome!
If we are using the full build i.e including Vue directly using the script tag without using a build tool, we should make sure we use the minified version (vue. min. js) for production. We can run the bundling command with the actual NODE_ENV environment variable set to "production".
Vue styleguidist uses webpack under the hood and it needs to know how to load your project's files. Webpack is required to run Vue styleguidist but your project doesn't have to use it. Note: See cookbook for more examples.
The problem may be in your 'webpack.base.conf.js' as i suspected, thank you for sharing it, upon searching i've found an issue resolving your 'production not being detected' problem on github here
The solution requires that you change 'vue$': 'vue/dist/vue'
to 'vue$': vue/dist/vue.min
in production.
You will find the original answer as:
@ozee31 This alias 'vue$': 'vue/dist/vue' cause the problem, use vue/dist/vue.min in production environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With