码迷,mamicode.com
首页 > 其他好文 > 详细

taro2.0.0版本的config的配置

时间:2020-02-04 16:04:42      阅读:763      评论:0      收藏:0      [点我收藏+]

标签:geo   env   func   att   product   OLE   rod   rewrite   nod   

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‘
}
},
}
*****
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, [])
* }
*/
}
}
 
*******
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配置文档参考:
 
 

taro2.0.0版本的config的配置

标签:geo   env   func   att   product   OLE   rod   rewrite   nod   

原文地址:https://www.cnblogs.com/pikachuworld/p/12259573.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!