-
-
Save zobzn/30eb57c925487529cd34655d5132cbe9 to your computer and use it in GitHub Desktop.
Cloud Function built by webpack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"functions": { | |
"source": "functions" | |
}, | |
"hosting": { | |
"public": "build", | |
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"], | |
"rewrites": [ | |
{ | |
"source": "/api/hello", | |
"function": "hello" | |
} | |
] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// server/index.js | |
import * as functions from 'firebase-functions' | |
export const hello = functions.https.onRequest((req, res) => { | |
res.send('hello').end() | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"private": true, | |
"scripts": { | |
"deploy:functions": "webpack --config server/webpack.config.js && cd functions && yarn install && firebase deploy --only functions" | |
}, | |
"devDependencies": { | |
"babel-loader": "^7.1.2", | |
"generate-json-webpack-plugin": "^0.2.2", | |
"webpack": "^3.8.1" | |
}, | |
"dependencies": { | |
"firebase-admin": "^5.5.1", | |
"firebase-functions": "^0.7.3" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// server/webpack.config.js | |
const pkg = require('../package') | |
const GenerateJsonPlugin = require('generate-json-webpack-plugin') | |
const externals = ['firebase-admin', 'firebase-functions'] | |
const genPackage = () => ({ | |
name: 'functions', | |
private: true, | |
main: 'index.js', | |
license: 'MIT', | |
dependencies: externals.reduce( | |
(acc, name) => | |
Object.assign({}, acc, { | |
[name]: pkg.dependencies[name] || pkg.devDependencies[name] | |
}), | |
{} | |
) | |
}) | |
module.exports = { | |
entry: [__dirname + '/index.js'], | |
output: { | |
path: __dirname + '/../functions', | |
filename: 'index.js', | |
libraryTarget: 'commonjs' | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
use: 'babel-loader', | |
include: __dirname + '/src' | |
} | |
] | |
}, | |
externals: externals.reduce( | |
(acc, name) => Object.assign({}, acc, { [name]: true }), | |
{} | |
), | |
plugins: [new GenerateJsonPlugin('package.json', genPackage())] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment