前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >vue3 配置生成环境打包不输出日志

vue3 配置生成环境打包不输出日志

作者头像
用户10106350
发布2022-10-28 10:16:21
4840
发布2022-10-28 10:16:21
举报
文章被收录于专栏:WflynnWeb

代码已上传至github github代码地址:https://github.com/Miofly/mio.git

最近做项目由于要求生产环境中不允许在控制台输出内容,而一个一个注释console.log非常麻烦所以就找到一个插件在生产环境打包时去除所有日志输出。

以下为具体配置

在vue.config.js配置文件中添加

代码语言:javascript
复制
configureWebpack: config => {
        if (process.env.NODE_ENV === 'production') { // 生产环境不输出日志
            config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
        }
    },

完整配置

代码语言:javascript
复制
const path = require('path')
// 配置uni-router的路由页面
const TransformPages = require('uni-read-pages')
// const uni-simple-router = require('uni-read-pages')
const tfPages = new TransformPages({
    includes: ['path', 'name', 'meta']
})

function resolve(dir) {
    return path.join(__dirname, dir)
}

module.exports = {
    publicPath: './',
    transpileDependencies: ['uni-simple-router'],
    configureWebpack: config => {
        if (process.env.NODE_ENV === 'production') { // 生产环境不输出日志
            config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
        }
    },
    devServer: {
        proxy: {
            '/api': {
                // target: "http://10.19.193.135:8870/ssyth",
                target: 'http://www.okzyw.com',
                changeOrigin: true, // 是否跨域
                pathRewrite: {
                    '^/api': ''
                }
            },
            '/foo': {
                // target: "http://10.19.193.135:8870/ssyth",
                target: 'https://api.apiopen.top',
                changeOrigin: true, // 是否跨域
                pathRewrite: {
                    '^/foo': ''
                }
            },
            '/db': {
                // target: "http://10.19.193.135:8870/ssyth",
                target: 'https://movie.douban.com',
                changeOrigin: true, // 是否跨域
                ws: true,
                pathRewrite: {
                    '^/db': ''
                }
            },
            // '/lz': {
            //     // target: "http://10.19.193.135:8870/ssyth",
            //     target: 'http://new-lz-test.52eja.com/api',
            //     changeOrigin: true, // 是否跨域
            //     ws: true,
            //     pathRewrite: {
            //         '^/lz': ''
            //     }
            // },
            '/lz': {
                // target: "http://10.19.193.135:8870/ssyth",
                target: 'http://api.lezhuan2020.cn/api',
                changeOrigin: true, // 是否跨域
                ws: true,
                pathRewrite: {
                    '^/lz': ''
                }
            }
        }
    },
    chainWebpack: config => {
        config.resolve.alias
            .set('@', resolve('src'))
            .set('zj', resolve('src/components'))
            .set('mioJs', resolve('src/common/js'))
            .set('json', resolve('src/static/mockJson'))
        config.plugin('provide').use(tfPages.webpack.DefinePlugin, [{
            ROUTES: JSON.stringify(tfPages.routes)
        }])
    },
}
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-04-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 WflynnWeb 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档