Last active
February 23, 2021 07:03
-
-
Save mizchi/1929d54ff93e32217ec985094b473fd5 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
i face the following error: [webpack-cli] TypeError: Cannot read property 'PROCESS_ASSETS_STAGE_ADDITIONAL' of undefined