package.json中针对本地环境与云环境的不同入口点

时间:2018-05-06 16:44:26

标签: firebase google-cloud-functions babel package.json firebase-cli

我已经在ES2017代码中编写了我的firebase函数,因为我无法使用ES2017 JavaScript部署函数,所以我必须将其编写。我理解它的方式是import UIKit class ViewController: UIViewController { @IBOutlet weak var GoButton: UIButton! @IBOutlet weak var Background: UIImageView! @IBOutlet weak var SettingsButton: UIButton! @IBOutlet weak var aboutButton: UIButton! @IBAction func toFlashcards(_ sender: Any) { self.Background.image = nil } override func viewDidLoad() { super.viewDidLoad() } override func viewWillLayoutSubviews() { if(view.frame.size.width == 375 || view.frame.size.width == 812)&&(view.frame.size.height == 375 || view.frame.size.height == 812){ iphoneX() } if(view.frame.size.width == 320 || view.frame.size.width == 568)&&(view.frame.size.height == 320 || view.frame.size.height == 568){ iphoneSE() } if(view.frame.size.width == 414 || view.frame.size.width == 736)&&(view.frame.size.height == 414 || view.frame.size.height == 736){ iphone8Plus() } if(view.frame.size.width == 375 || view.frame.size.width == 667)&&(view.frame.size.height == 375 || view.frame.size.height == 667){ iphone8() } if(view.frame.size.width == 1024 || view.frame.size.width == 1366)&&(view.frame.size.height == 1024 || view.frame.size.height == 1366){ ipadPro() } if(view.frame.size.width == 1112 || view.frame.size.width == 834)&&(view.frame.size.height == 1112 || view.frame.size.height == 834){ ipad10inch() } if(view.frame.size.width == 768 || view.frame.size.width == 1024)&&(view.frame.size.height == 768 || view.frame.size.height == 1024){ ipad9inch() } } func iphoneX(){ Background.contentMode = .scaleToFill Background.image = #imageLiteral(resourceName: "iphoneXBackground") GoButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 50) GoButton.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 220).isActive = true GoButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 150).isActive = true view.bottomAnchor.constraint(equalTo: GoButton.bottomAnchor, constant: 88).isActive = true SettingsButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 30) view.trailingAnchor.constraint(equalTo: SettingsButton.trailingAnchor, constant: 575).isActive = true SettingsButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 90).isActive = true SettingsButton.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 139).isActive = true aboutButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 30) view.bottomAnchor.constraint(equalTo: aboutButton.bottomAnchor, constant: 34).isActive = true aboutButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 300).isActive = true aboutButton.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 280).isActive = true } func iphoneSE(){ Background.contentMode = .scaleToFill Background.image = #imageLiteral(resourceName: "iphoneXBackground") view.bottomAnchor.constraint(equalTo: GoButton.bottomAnchor, constant: 75).isActive = true GoButton.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 195).isActive = true GoButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 95).isActive = true view.trailingAnchor.constraint(equalTo: SettingsButton.trailingAnchor, constant: 400).isActive = true SettingsButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 60).isActive = true SettingsButton.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 120).isActive = true view.bottomAnchor.constraint(equalTo: aboutButton.bottomAnchor, constant:40).isActive = true aboutButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 205).isActive = true aboutButton.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 245).isActive = true aboutButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 25) GoButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 45) SettingsButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 25) } func iphone8Plus(){ Background.contentMode = .scaleToFill Background.image = #imageLiteral(resourceName: "iphoneXBackground") GoButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 50) view.bottomAnchor.constraint(equalTo: GoButton.bottomAnchor, constant: 94).isActive = true GoButton.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 245).isActive = true GoButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 130).isActive = true SettingsButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 30) view.trailingAnchor.constraint(equalTo: SettingsButton.trailingAnchor, constant: 525).isActive = true SettingsButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 75).isActive = true SettingsButton.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 157).isActive = true aboutButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 32) view.bottomAnchor.constraint(equalTo: aboutButton.bottomAnchor, constant: 46).isActive = true aboutButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 267).isActive = true aboutButton.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 315).isActive = true } func iphone8(){ Background.contentMode = .scaleToFill Background.image = #imageLiteral(resourceName: "iphoneXBackground") GoButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 50) view.bottomAnchor.constraint(equalTo: GoButton.bottomAnchor, constant: 85).isActive = true GoButton.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 215).isActive = true GoButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 112).isActive = true SettingsButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 30) view.trailingAnchor.constraint(equalTo: SettingsButton.trailingAnchor, constant: 465).isActive = true SettingsButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 65).isActive = true SettingsButton.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 139).isActive = true aboutButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 30) view.bottomAnchor.constraint(equalTo: aboutButton.bottomAnchor, constant: 35).isActive = true aboutButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 239).isActive = true aboutButton.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 284).isActive = true } func ipadPro(){ Background.contentMode = .scaleToFill GoButton.frame.size.width = 170 GoButton.frame.size.height = 170 GoButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 100) view.bottomAnchor.constraint(equalTo: GoButton.bottomAnchor, constant: 209).isActive = true view.trailingAnchor.constraint(equalTo: GoButton.trailingAnchor, constant: 961).isActive = true GoButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 200).isActive = true SettingsButton.frame.size.width = 220 SettingsButton.frame.size.height = 147 SettingsButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 60) view.trailingAnchor.constraint(equalTo: SettingsButton.trailingAnchor, constant: 935).isActive = true SettingsButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 118).isActive = true SettingsButton.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 420).isActive = true aboutButton.frame.size.width = 222 aboutButton.frame.size.height = 129 aboutButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 60) view.trailingAnchor.constraint(equalTo: aboutButton.trailingAnchor, constant: 667).isActive = true aboutButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 445).isActive = true view.bottomAnchor.constraint(equalTo: aboutButton.bottomAnchor, constant: 94).isActive = true } func ipad10inch(){ Background.contentMode = .scaleToFill GoButton.frame.size.width = 220 GoButton.frame.size.height = 110 GoButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 82) view.bottomAnchor.constraint(equalTo: GoButton.bottomAnchor, constant: 174).isActive = true view.trailingAnchor.constraint(equalTo: GoButton.trailingAnchor, constant: 810).isActive = true GoButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 161).isActive = true SettingsButton.frame.size.width = 220 SettingsButton.frame.size.height = 110 SettingsButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 55) view.trailingAnchor.constraint(equalTo: SettingsButton.trailingAnchor, constant: 737).isActive = true SettingsButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 92).isActive = true SettingsButton.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 335).isActive = true aboutButton.frame.size.width = 200 aboutButton.frame.size.height = 108 aboutButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 55) view.trailingAnchor.constraint(equalTo: aboutButton.trailingAnchor, constant: 515).isActive = true aboutButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 338).isActive = true view.bottomAnchor.constraint(equalTo: aboutButton.bottomAnchor, constant: 80).isActive = true } func ipad9inch(){ Background.contentMode = .scaleToFill GoButton.frame.size.width = 220 GoButton.frame.size.height = 110 GoButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 82) view.bottomAnchor.constraint(equalTo: GoButton.bottomAnchor, constant: 160).isActive = true view.trailingAnchor.constraint(equalTo: GoButton.trailingAnchor, constant: 738).isActive = true GoButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 155).isActive = true SettingsButton.frame.size.width = 220 SettingsButton.frame.size.height = 110 SettingsButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 55) view.trailingAnchor.constraint(equalTo: SettingsButton.trailingAnchor, constant: 700).isActive = true SettingsButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 85).isActive = true SettingsButton.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 305).isActive = true aboutButton.frame.size.width = 200 aboutButton.frame.size.height = 108 aboutButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 55) view.trailingAnchor.constraint(equalTo: aboutButton.trailingAnchor, constant: 495).isActive = true aboutButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 312).isActive = true view.bottomAnchor.constraint(equalTo: aboutButton.bottomAnchor, constant: 65).isActive = true } } 提供在我的本地环境(使用ES2017)中运行的功能,firebase serve将功能部署到云(没有ES2017)。

在部署之前,我firebase deploy和babel在主文件夹中抓取我的index.js文件,将其转换并放入/ dist文件夹以及一些配置文件。

为了从./dist文件夹中部署firebase,我在package.json中设置了入口点npm run prepare。但是,这意味着当我想要"main": "./dist/index.js"用于本地环境时,我会从./dist文件夹中提供已转换的函数。所以我必须在firebase serve"main": "index.js"之间不断更改,具体取决于我是想在本地提供函数还是部署转换后的函数。

尽管已经指定了我想要服务和部署的位置,如下所示:

"main": "./dist/index.js"

我的整个package.json文件:

  "scripts": {
    "lint": "./node_modules/.bin/eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase experimental:functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions/dist",
    "logs": "firebase functions:log"
  }

0 个答案:

没有答案