• taro2.0.0版本的config的配置


    dev.js
    const HOST = '"http://dev"'
    // const HOST_M = '"http://dev"'
    const GLOBAL_ENV = 1 
    module.exports = {
        env: {
            NODE_ENV: '"development"'
        },
        defineConstants: {
            HOST,
            GLOBAL_ENV
        },
        weapp: {},
        h5: {
            devServer:{
                host: "0.0.0.0",
                port: 10086
            },
            router: {
            mode: 'hash' // 或者是 'browser'
            }
        },
    }
    <hr>
    prod.js
    const isH5 = process.env.CLIENT_ENV === 'h5'
    const HOST = '"http://"'
    console.log('-----prod--process.env.CLIENT_ENV----', process.env.CLIENT_ENV)
    // const HOST = '"https://"'
    const GLOBAL_ENV = 3// 3是上线
    // const HOST = [1, 2].includes(GLOBAL_ENV) ? '"http://dev"' : '"https://"'
    // eslint-disable-next-line
    module.exports = {
        env: {
            NODE_ENV: '"production"'
        },
        defineConstants: {
            HOST,
            GLOBAL_ENV
        },
        weapp: {},
        h5: {
        publicPath: './'
        /**
        * 如果h5端编译后体积过大,可以使用webpack-bundle-analyzer插件对打包体积进行分析。
        * 参考代码如下:
        * webpackChain (chain) {
        * chain.plugin('analyzer')
        * .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, [])
        * }
        */
        }
    }
    
    <hr>
    index.js
    const path = require("path")
    // import path from 'path';
    const config = {
        projectName: 'taro-framework',
        date: '2019-12-2',
        designWidth: 750,
        deviceRatio: {
            640: 2.34 / 2,
            750: 1,
            828: 1.81 / 2
        },
        sourceRoot: 'src',
        outputRoot: 'dist',
        // TODO 特别要修改babel的配置
        babel: {
            sourceMap: true,
            presets: [
            [
            'env',
            {
            modules: false
            }
            ]
            ],
            plugins: [
            'transform-class-properties',
            'transform-decorators-legacy',
            'transform-object-rest-spread'
            ]
        
        },
        // TODO 将JSON.stringify()去掉
        defineConstants: {
            'process.env.SERVER_ENV': JSON.stringify(process.env.SERVER_ENV),
        },
        // TODO 小程序名称改为mini,可以删掉很多小配置
        mini: {
            postcss: {
                pxtransform: {
                enable: true,
                config: {
                }
            },
            url: {
                enable: true,
                config: {
                limit: 10240 // 设定转换尺寸上限
                }
            },
            cssModules: {
                enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
                config: {
                    namingPattern: 'module', // 转换模式,取值为 global/module
                    generateScopedName: '[name]__[local]___[hash:base64:5]'
                }
                }
            }
        },
        // 可以删掉很多小配置
        h5: {
            esnextModules: ['taro-ui'],
            publicPath: '/',
            staticDirectory: 'static',
            devServer: {
            host: '0.0.0.0',
            port: 10086,
            proxy: {
                '/mj-c2b': {
                    target: 'https://dev.fe.musee.com.cn/', // 服务端地址
                    changeOrigin: true,
                    pathRewrite: {
                    ['^']: ''
                    }
                },
                'hb': {
                    target: 'http://dev.api.musee.com.cn', // 服务端地址
                    changeOrigin: true,
                    pathRewrite: {
                    ['^']: ''
                    }
                }
            },
        },
            postcss: {
                autoprefixer: {
                    enable: true,
                    config: {
                        browsers: [
                        'last 3 versions',
                        'Android >= 4.1',
                        'ios >= 8'
                        ]
                    }
                },
                cssModules: {
                    enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
                    config: {
                        namingPattern: 'module', // 转换模式,取值为 global/module
                        generateScopedName: '[name]__[local]___[hash:base64:5]'
                    }
                }
            }
        },
        alias: {
        '@/components': path.resolve(__dirname, '..', 'src/components'),
        '@/utils': path.resolve(__dirname, '..', 'src/utils'),
        '@/package': path.resolve(__dirname, '..', 'package.json'),
        '@/project': path.resolve(__dirname, '..', 'project.config.json'),
        }
        }
        //
        module.exports = function (merge) {
        if (process.env.NODE_ENV === 'development') {
        return merge({}, config, require('./dev'))
        }
        return merge({}, config, require('./prod'))
        }

     

    trao配置文档参考:
    http://taro-docs.jd.com/taro/docs/config-detail.html
  • 相关阅读:
    [bzoj4241] 历史研究 (分块)
    [tyvj2054] 四叶草魔杖 (最小生成树 状压dp)
    20180710 考试记录
    [luogu2047 NOI2007] 社交网络 (floyed最短路)
    [luogu2081 NOI2012] 迷失游乐园 (树形期望dp 基环树)
    [luogu1600 noip2016] 天天爱跑步 (树上差分)
    [luogu2216 HAOI2007] 理想的正方形 (2dST表 or 单调队列)
    [poj 3539] Elevator (同余类bfs)
    [BZOJ1999] 树网的核 [数据加强版] (树的直径)
    bzoj2301 [HAOI2011]Problem b
  • 原文地址:https://www.cnblogs.com/pikachuworld/p/12259573.html
Copyright © 2020-2023  润新知