From 3c1cfabf2650a7ada6661aa151ef3a4af9f4fa35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Fri, 13 Jul 2018 00:43:16 +0800 Subject: [PATCH] Optimization: chnage firebase site script --- firebase.json | 8 ++++++- functions/package.json | 4 ++-- package.json | 2 +- scripts/all_mock.js | 48 ++++++++++++++++++++++++++-------------- scripts/rollup.config.js | 2 +- 5 files changed, 43 insertions(+), 21 deletions(-) diff --git a/firebase.json b/firebase.json index 94da47eb..a00223d4 100644 --- a/firebase.json +++ b/firebase.json @@ -1,7 +1,13 @@ { "hosting": { "public": "dist", - "rewrites": [{ "source": "/api/**", "function": "api" }], + "rewrites": [ + { "source": "/api/**", "function": "api" }, + { + "source": "**", + "destination": "/index.html" + } + ], "ignore": ["firebase.json", "**/.*", "**/node_modules/**"] } } diff --git a/functions/package.json b/functions/package.json index 5e142869..aaa103a4 100644 --- a/functions/package.json +++ b/functions/package.json @@ -2,12 +2,12 @@ "name": "functions", "description": "Cloud Functions for Firebase", "scripts": { - "serve": "npm run mock && firebase serve --only functions", + "serve": "firebase serve --only functions", "shell": "firebase functions:shell", "start": "npm run shell", "deploy": "firebase deploy --only functions", "logs": "firebase functions:log", - "mock": "cd .. && rollup -c" + "mock": "cd ../scripts && rollup -c" }, "dependencies": { "express": "^4.16.3", diff --git a/package.json b/package.json index b139bd53..c870f380 100755 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "start": "cross-env ESLINT=none umi dev", "start:no-mock": "cross-env MOCK=none ESLINT=none umi dev", "build": "cross-env ESLINT=none umi build", - "site": "npm run presite && rollup -c && npm run build && firebase deploy", + "site": "npm run presite && npm run build && firebase deploy", "analyze": "cross-env ANALYZE=1 umi build", "lint:style": "stylelint \"src/**/*.less\" --syntax less", "lint": "eslint --ext .js src mock tests && npm run lint:style", diff --git a/scripts/all_mock.js b/scripts/all_mock.js index 095d4c67..98975684 100644 --- a/scripts/all_mock.js +++ b/scripts/all_mock.js @@ -1,17 +1,33 @@ -import api from 'mock/api'; -import chart from 'mock/chart'; -import geographic from 'mock/geographic'; -import notices from 'mock/notices'; -import profile from 'mock/profile'; -import rule from 'mock/rule'; -import user from 'mock/user'; +import api from '../mock/api'; +import chart from '../mock/chart'; +import geographic from '../mock/geographic'; +import notices from '../mock/notices'; +import profile from '../mock/profile'; +import rule from '../mock/rule'; +import user from '../mock/user'; -export default { - ...api, - ...chart, - ...geographic, - ...notices, - ...profile, - ...rule, - ...user, -}; +const data = {}; +Object.keys(api).forEach(key => { + data[key] = api[key]; +}); +Object.keys(chart).forEach(key => { + data[key] = chart[key]; +}); + +Object.keys(geographic).forEach(key => { + data[key] = geographic[key]; +}); +Object.keys(notices).forEach(key => { + data[key] = notices[key]; +}); +Object.keys(profile).forEach(key => { + data[key] = profile[key]; +}); +Object.keys(rule).forEach(key => { + data[key] = rule[key]; +}); +Object.keys(user).forEach(key => { + data[key] = user[key]; +}); + +export default data; diff --git a/scripts/rollup.config.js b/scripts/rollup.config.js index dad0073d..98d49541 100644 --- a/scripts/rollup.config.js +++ b/scripts/rollup.config.js @@ -3,7 +3,7 @@ import json from 'rollup-plugin-json'; export default { input: './all_mock.js', output: { - file: './functions/mock/index.js', + file: '../functions/mock/index.js', format: 'umd', name: 'mock', }, -- GitLab