This is a Start-Up kit for a Firebase web project, which uses Vue3 and firebase 9.
- Node.js version 14 or later.
- Git clone this repository
- Run "yarn global add firebase-tools" to install firebase tools.
- Run "yarn install" once to get necessary node modules.
- Run "yarn install" once in the functions directory as well.
- Open the firebase console (from https://firebase.google.com) and add a project
- From the dashboard of this project, add an app and choose "web" (</>).
- From the setting of this app, choose "Config" (in Firebase SDK snippet)
- Copy the config file, and paste into src/config/project.ts file.
- Replace the word "fir-vue-startup-kit" in .firebaserc file with your Firebase project name.
- Open the firebase console, and create a Cloud Firestore (make it "secure" for now).
- Enable Firebase Hosting on the firebase console.
Because Firebase Functions is very slow in the case of cold start by default setting, this startup-kit is a bit of a custom Firebase functions.
- Functions is invoked using a wrapper function (
exportIfNeeded
function infunctions/src/common/exportifneeded.ts
). It loads only the functions it needs. - Functions will start with enough memory.
test
function infunctions/src/wrappers/tests/test.ts
run with 1GB memory. - Functions run in a nearby region. In my case it is Japan, so it is set in the Japanese region. Please change it to suit your location.
For this reason, Functions are used in a slightly unusual way.
Functions called by the client are written in src/index.ts
like exportIfNeeded ("test", "tests/test", exports);
In this case, the client calls test as a function. And when the client call the test Function, the default function in functions/src/wrappers/tests/test.ts
is called. See this file for more information.
- The functions settings are in
src/utils/firebase.ts
. By default, it set to call asia-northeast1 (Tokyo) region. - All functions put together in
src/utils/functions.ts
. You should add new functions in this file.
The region of Functions is set in asia-northeast1(Tokyo). If you change the region, be sure to change both Vue.js in Functions.
- This startup-kit supports i18n using url path.
- You can use one Vue file in both
/en/index
and/jp/index
. - Language files are in
src/i18n/
directory.en.ts
andja.ts
are Language files.- The language file used for the language switching pull-down (select) is
language.ts
. The same file is read fromen.ts
andja.ts
. Write in each language. - If you want to add new language, add the language to
index.ts
, add the{language}.ts
, and add language tolanguage.ts
.
- See also
src/router/index.ts
for how to switch languages with url path. - You can use the language switching pull-down in
src/components/Languages.vue
. This file needs to readroute.param.lang
, so don't use it inApp.vue
andLayout.vue
. Other than that, it can be used anywhere. - i18n uses
vue-i18n@next
, so please refer to that for details on how to use it.
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:8080 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
Builds the app for production to the dist
folder.
It correctly bundles Vue in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
Deploys the app to the Firebase cloud. You need to run "yarn run build" before the deployment.
Run Prettier, rewrite code as code formatting.
- Create and download the new service account's JSON key
- Add that JSON key as a secret in your GitHub repository. JSON key is FIREBASE_SERVICE_ACCOUNT_FIR_VUE_STARTUP_KIT.
- Add firebase project id as a secret in your GitHub repository. JSON key is FIREBASE_PROJECT.
More detail: see, https://github.com/marketplace/actions/deploy-to-firebase-hosting
This is the sample site I deployed.