fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * @Descripttion:
 * @version: 1.0.0
 * @Author: Bridge
 * @Date: 2021-07-14 11:09:55
 */
 
const path = require('path')
const pxtovw = require('postcss-px-to-viewport')
const debug = process.env.NODE_ENV !== 'production'
    /* eslint-disable */
module.exports = {
    publicPath: process.env.NODE_ENV === 'development' ? '/' : './',
    assetsDir: 'static',
    outputDir: 'www',
    productionSourceMap: false,
    css: {
        loaderOptions: {
            postcss: {
                // 给postcss-loader传递选项
                plugins: [
                    new pxtovw({
                        unitToConvert: 'px', // 需要转换的单位,默认为"px";
                        viewportWidth: 750, // 设计稿的视口宽度
                        unitPrecision: 5, // 单位转换后保留的小数位数
                        propList: ['*'], // 要进行转换的属性列表,*表 示匹配所有,!表示不转换
                        viewportUnit: 'vw', // 转换后的视口单位
                        fontViewportUnit: 'vw', // 转换后字体使用的视口单位
                        selectorBlackList: [], // 不进行转换的css选择器,继续使用原有单位
                        minPixelValue: 1, // 设置最小的转换数值
                        mediaQuery: false, // 设置媒体查询里的单位是否需要转换单位
                        replace: true, // 是否直接更换属性值,而不添加备用属性
                        exclude: [/node_modules/] // 忽略某些文件夹下的文件
                    })
                ]
            }
        }
    },
    chainWebpack: config => {
        // 移除 prefetch 插件
        config.plugins.delete('prefetch')
    },
    configureWebpack: config => {
        // webpack配置,值位对象时会合并配置,为方法时会改写配置
        if (debug) {
            // 开发环境配置
            config.devtool = 'cheap-module-eval-source-map'
        } else {
            // 生产环境配置
        }
 
        config.externals = {
            'uni': 'uni',
        }
        Object.assign(config, {
            // 开发生产共同配置,配置别名
            resolve: {
                alias: {
                    '@': path.resolve(__dirname, './src'),
                    '@api': path.resolve(__dirname, './src/api'),
                    vue$: 'vue/dist/vue.esm.js'
                }
            }
        })
    },
    devServer: {
        open: true,
        https: false,
        hotOnly: false,
        // host: 'localhost',
        port: 19999,
        headers: {
            'Access-Control-Allow-Origin': '*',
        },
        proxy: {
            '/api': {
                target: process.env.VUE_APP_API_BASE_URL,
                changeOrigin: true,
                logLevel: 'debug',
                ws: true,
                pathRewrite: {
                    '^/api': ''
                }
            }
        },
        before: app => {}
    },
    lintOnSave: false
}