ssbb
ssbb

Reputation: 1931

configure webpack only for production using vue-cli3

I try to compile my vue project a bit differently in local and in production.

As you will see, There is a massive difference in my vue.config.js file...joke

// this is the file when I'm in dev version
module.exports = {
    lintOnSave: false,
}
// this is the file when I'm in prod version
module.exports = {
    lintOnSave: false,
    configureWebpack: {
        output: {
            publicPath: '/static/'
        }
    }
}

I was checking for the new mode in webpack 4, or in the vue cli documentation, I didn't find anything which avoid to change the vue.config.js MANUALLY whenever I want to build local or prod. This is not CI ready, and I feel sh*t doing it, so If you guys have any tips to do it properly.

Thanks.

Upvotes: 0

Views: 553

Answers (1)

ssbb
ssbb

Reputation: 1931

well, I'm not sure that The things to do, but you can use the variable 'process.env.NODE_ENV' in the vue.config.js file (which I didn't expect). so

if (process.env.NODE_ENV === 'production') {
module.exports = {
    configureWebpack: {
        output: {
            publicPath: '/static/'
        }
    }
}
}
else{
module.exports = {
    lintOnSave: true
}
}

looks to work properly

Upvotes: 1

Related Questions