前端Vue
Vue.js(读音 /vju?/, 类似于 view) 是一套构建用户界面的渐进式框架。
针对问题
SyntaxError: Unexpected token p in JSON
- 需要区分 开发、QA、预发布、生产等多个环境,如何满足?
- 怎么部署到服务器上自动判断呢?
- Vue 只关注视图层 , 采用自底向上增量开发的设计。
- Vue API 实现了数据绑定和视图组件,所以,很多人用 npm install 后都会出现package的系列问题。
package.json描述
多环境部署
区分 开发、QA、预发布、生产等多个环境if (process.env.ENV === ‘development‘) {}if (process.env.ENV === ‘QA‘) {}if (process.env.ENV === ‘pre-release‘) {}if (process.env.ENV === ‘production‘) {}
查看源码获取解决方案
const path = require(‘path‘)
module.exports = function (content) { if (process.env.UNI_USING_COMPONENTS || process.env.UNI_PLATFORM === ‘h5‘) { return require(‘./index-new‘).call(this, content) } this.cacheable && this.cacheable() const manifestJsonPath = path.resolve(process.env.UNI_INPUT_DIR, ‘manifest.json‘) const manifestJson = parseManifestJson(fs.readFileSync(manifestJsonPath, ‘utf8‘)) this.addDependency(manifestJsonPath) const pagesJson = parsePagesJson(content) if(manifestJson.transformPx === false) { process.UNI_TRANSFORM_PX = false } else { process.UNI_TRANSFORM_PX = true } if (process.env.UNI_PLATFORM === ‘h5‘) { returnrequire(‘./platforms/h5‘)(pagesJson, manifestJson) } const changedEmitFiles = [] function checkPageEmitFile (pagePath, pageStyle) { checkEmitFile(pagePath, parseStyle(pageStyle), changedEmitFiles) } parsePages(pagesJson, function (page) { checkPageEmitFile(page.path, page.style) }, function (root, page) { checkPageEmitFile(normalizePath(path.join(root, page.path)), page.style) }) const jsonFiles = require(‘./platforms/‘ + process.env.UNI_PLATFORM)(pagesJson, manifestJson) if (jsonFiles && jsonFiles.length) { jsonFiles.forEach(jsonFile => { jsonFile && checkEmitFile(jsonFile.name, jsonFile.content, changedEmitFiles) }) } changedEmitFiles.forEach(name => { this.emitFile(name + ‘.json‘, emitFileCaches[name]) }) return ‘‘}
if (manifestJson.transformPx === false) { process.UNI_TRANSFORM_PX = false } else { process.UNI_TRANSFORM_PX = true } if (process.env.UNI_PLATFORM === ‘h5‘) { returnrequire(‘./platforms/h5‘)(pagesJson, manifestJson) }
npm install --save-dev cross-env
"build": "cross-env BUILD_ENV=production node build/build.js","QA": "cross-env BUILD_ENV=QA node build/build.js","TEST": "cross-env BUILD_ENV=TEST node build/build.js"
cross-env xxx=xxx node build/build.js
let ENV = process.env.BUILD_ENV; if (ENV == ‘production‘) { // 生产环境 } else if (ENV == ‘QA‘) { // 测试环境 }else if(ENV== ‘TEST‘){ // 开发测试 }
更多技术资讯可关注:gzitcast