Deploy your first website with Firebase. We are going to use GitHub, Firebase, Travis CI or GitHub Actions, Nodejs and GoDaddy like tech tools.
- Create the repository. Add the collaborators.
- Clone the repo. Create a folder called
src
. Inside that floder create aindex.html
file and aassets
folder. Withinassets
folder, create two folders calledjs
andcss
. There you are going to save the js files and css files. - Create a new project in the firebase console.
- Set up Firebase Hosting: Go to the
hosting
tab. Follow the steps to set up the hosting. 4.1 Run (using cmd):npm install -g firebase-tools
.firebase login
. If the command is not being executed runfirebase login --interactive
.firebase init
(Run this command from your app’s root directory).- Select
hosting
with spacebar. - Select your existing project.
- Deploy with
firebase deploy
.
- Remove the content inside
index.html
in thepublic
. Create a basic layout and deploy again.
- Install NodeJs.
- Run
npm init -y
inside your app folder. - Create a
prepare.js
file in the root folder. - Install
ncp
andrimraf
dependencies (search first the utility. npm website or read this article). 4.1 Runnpm i ncp
andnpm i rimraf
. - Copy this code into your
prepare.js
.
const rimraf = require('rimraf'); //remove files
const ncp = require('ncp').ncp; //copy files
const fs = require('fs');
const public_dir = './public';
const file_list = [
{ fileSource: './src/index.html', fileDest: './public/index.html' },
];
//removes public folder
rimraf('./public/', function (rimraf_error) {
if (rimraf_error) { throw rimraf_error; }
// done
//if public folder doesn't exist
if (!fs.existsSync(public_dir)) {
//creates public folder
fs.mkdirSync(public_dir);
}
file_list.forEach((fileElement, index, array) => {
const { fileSource, fileDest } = fileElement;
copy_files(fileSource, fileDest);
});
})
function copy_files(sourcePath, destPath){
ncp(sourcePath, destPath, function (ncp_error) {
if (ncp_error) { throw ncp_error; }
});
}
- Run
node prepare.js
to see how it works. - Configure your
package.json
. 7.1 Add into the scripts attribute:"prepare-public": "node prepare.js"
. 7.2 Try it. Runnpm run prepare-public
.
- Sign up to Travis.
- Select your repo and authorize Travis CI
- Generate the firebase token running
firebase login:ci
. - Copy the token and add an enviroment variable in Travis
- Create a
.travis.yml
file in the root folder. - Paste the following code:
language: node_js
node_js:
- "8"
script:
- echo "Deploy!!"
install:
- npm install -g firebase-tools
- npm install
- npm run prepare-public
after_success:
- firebase deploy --project your_project_name --token $FIREBASE_TOKEN
- Make sure to create the enviroment variable in TravisCI and to change
your_project_name
varialble in the command.
- Push your changes.
git add . git commit -m "first deploy with Travis" git push -u origin master
- Create a
secret
variable in your repo settings.
- Create an
action
in your Actions tab with the following structure
name: Node.js CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm install -g firebase-tools
- run: npm install
- run: npm run prepare-public
- run: firebase deploy --token ${{ secrets.FIREBASE_TOKEN }}
env:
CI: true
- Enjoy.
- Go to the firebase console and
add a custom domain
- Add the verification to the DNS in GoDaddy.
- Add the
A
registers pointing to the values.
- If you have problems change the
name
to@