wepy框架开发小程序配置自动匹配正式环境,开发环境请求url
2019-07-31 13:57
537 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_43926335/article/details/97910965
注意安装
-
scr下面创建config文件夹 并创建dev.js prod.js index.js三个文件
dev.jsexport default { url: '开发环境url' }
prod.js
export default { url: '正式环境url' }
index.js
``` import devConf from './dev' import prodConf from './prod' import {merge} from 'lodash' let config = {} // 配置文件对象,它将会被devConf或prodConf替换 let env = process.env.NODE_ENV // 当前的项目环境 console.log('env=' + env) if (env === 'dev') { merge(config, devConf) } else if (env === 'production') { merge(config, prodConf) } export default config ```
-
wepy.config.js
``` const path = require('path') var prod = process.env.NODE_ENV === 'production' module.exports = { wpyExt: '.wpy', eslint: true, cliLogs: !prod, build: { web: { htmlTemplate: path.join('src', 'index.template.html'), htmlOutput: path.join('web', 'index.html'), jsOutput: path.join('web', 'index.js') } }, resolve: { alias: { counter: path.join(__dirname, 'src/components/counter'), '@': path.join(__dirname, 'src') }, aliasFields: ['wepy', 'weapp'], modules: ['node_modules'] }, compilers: { less: { compress: prod }, babel: { sourceMap: true, presets: [ 'env' ], plugins: [ // **重点在这** 'transform-class-properties', 'transform-decorators-legacy', 'transform-object-rest-spread', 'transform-export-extensions', 'transform-node-env-inline' ] } }, appConfig: { noPromiseAPI: ['createSelectorQuery'] } } if (prod) { module.exports.plugins = { uglifyjs: { filter: /\.js$/, config: { } }, 'imagemin': { filter: /\.(jpg|png|jpeg)$/, config: { 'jpg': { quality: 80 }, 'png': { quality: 80 } } } } } ```
3.package.json
``` { "name": "charge", "version": "0.0.2", "description": "A WePY project", "main": "dist/app.js", "scripts": { "dev": "cross-env NODE_ENV=dev wepy build --watch", "build": "cross-env NODE_ENV=production wepy build --no-cache", "dev:web": "wepy build --output web", "clean": "find ./dist -maxdepth 1 -not -name 'project.config.json' -not -name 'dist' | xargs rm -rf", "test": "echo \"Error: no test specified\" && exit 1" }, "wepy": { "module-a": false, "./src/components/list": "./src/components/wepy-list.wpy" }, "author": "zhouyumei", "license": "MIT", "dependencies": { "babel-plugin-transform-node-env-inline": "^0.4.3", "less": "^3.9.0", "redux": "^3.7.2", "redux-actions": "^2.2.1", "redux-promise": "^0.5.3", "wepy": "^1.6.0", "wepy-async-function": "^1.4.4", "wepy-com-toast": "^1.0.2", "wepy-redux": "^1.5.3" }, "devDependencies": { "across-env": "^1.0.8", "babel-eslint": "^7.2.1", "babel-plugin-global-define": "^1.0.3", "babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-decorators-legacy": "^1.3.4", "babel-plugin-transform-export-extensions": "^6.22.0", "babel-plugin-transform-object-rest-spread": "^6.26.0", "babel-preset-env": "^1.6.1", "cross-env": "^5.1.3", "eslint": "^3.18.0", "eslint-config-standard": "^7.1.0", "eslint-friendly-formatter": "^2.0.7", "eslint-plugin-html": "^2.0.1", "eslint-plugin-promise": "^3.5.0", "eslint-plugin-standard": "^2.0.1", "less": "^3.8.1", "wepy-compiler-babel": "^1.5.3", "wepy-compiler-less": "^1.3.12", "wepy-eslint": "^1.5.3", "wepy-plugin-imagemin": "^1.5.3", "wepy-plugin-uglifyjs": "^1.3.7" } }
4.开发环境执行 npm run dev 正式环境执行 npm run build
注意安装npm install babel-plugin-transform-node-env-inline --save
反正运行报错缺啥安装啥(手动滑稽)
- 使用 如有封装好的接口api文档里
//首先引入 import __CONFIG__ from '../config/index' //取得url const baseUrl=__CONFIG__ .url
相关文章推荐
- vue+axios 开发环境与生产环境配置请求接口,本地开发和线上开发有多个请求地址怎么处理?上线后自动获取ip,不需改请求地址可运用多个项目中
- 配置手机程序开发环境――WTK
- zend framework框架开发配置和windows下搭建PHP开发环境
- Visual Studio开发QT程序--环境配置
- RDIFramework.NET — 基于.NET的快速信息化系统开发框架- 5.4平台日志、异常管理、生成自动升级配置文件模块
- 用Perl、Shell脚本基于Tomcat6开发cgi程序环境配置
- 配置 hadoop 开发环境+运行 wordcount 程序
- 开发 DirectShow 程序的环境配置(Visual C++ 6 为例)
- VC6下开发OCCI程序的环境配置
- Android开发实战记录(一)-Android开发环境搭建之Windows-正式配置前的准备
- S2JH新增WIKI页面:开发基础环境配置说明,基于SSH的企业Web应用开发框架
- Android开发环境配置到第一个程序所遇到的问题
- eclipse完美配置PHP开发环境 ;(下载 安装 配置php自动提示代码 优化eclipse)
- Sencha Touch入门:Sencha Touch开发环境搭建及使用 Sencha Cmd 自动创建项目框架
- C、Shell、Perl基于Tomcat开发CGI程序环境配置
- eclipse中开发android程序时,打开layout配置文件自动关闭的问题
- android eclipse开发环境 自动提示 程序无法响应解决方法
- android eclipse开发环境 自动提示 程序无法响应解决方法
- Spring – 开发环境 – 自动配置