Tyler Flint
04/02/2021, 2:42 PMbundle: false doesn’t actually stop esbuild from building even for deploy.Tyler Flint
04/02/2021, 2:43 PMconst lambda = {
graphql: new sst.Function(this, "graphql", {
handler: 'index.main',
bundle: false,
srcPath: 'dist/graphql',
environment: env,
memorySize: 256,
timeout: 30,
}),
web: new sst.Function(this, "web", {
handler: 'index.main',
bundle: false,
srcPath: 'dist/web',
environment: env,
memorySize: 256,
timeout: 30,
}),
worker: new sst.Function(this, "worker", {
handler: 'index.main',
bundle: false,
srcPath: 'dist/worker',
environment: env,
memorySize: 256,
timeout: 500,
}),
migrate: new sst.Function(this, "migrate", {
handler: 'index.main',
bundle: false,
srcPath: 'dist/migrate',
environment: env,
memorySize: 512,
timeout: 500,
})
};Tyler Flint
04/02/2021, 2:44 PMbundle: false would just zip/upload the content of srcPath and inform lambda of the file/handler to call.Tyler Flint
04/02/2021, 2:45 PM.build directory in addition to my sourceTyler Flint
04/02/2021, 2:47 PMindex.js but with the sourcemap screwed up.Tyler Flint
04/02/2021, 2:48 PMTyler Flint
04/02/2021, 3:09 PMTyler Flint
04/02/2021, 3:10 PMbundle: false isn’t a simple “package up my source and tell lambda to use the handler specified”.Tyler Flint
04/02/2021, 3:11 PMTyler Flint
04/02/2021, 3:12 PMTyler Flint
04/02/2021, 3:15 PMTyler Flint
04/02/2021, 3:16 PMTyler Flint
04/02/2021, 3:23 PMTyler Flint
04/02/2021, 3:24 PMTyler Flint
04/02/2021, 3:30 PMTyler Flint
04/02/2021, 3:30 PMTyler Flint
04/02/2021, 3:31 PMTyler Flint
04/02/2021, 3:34 PMTyler Flint
04/02/2021, 3:38 PMsst start could end-run 90% of the functionality and just map a request to a file/handler. A legacy builder like webpack could be run in watch mode and achieve the same result.Tyler Flint
04/02/2021, 3:41 PMsst start with an external builder, just run sst start and webpack --watch concurrently, with the concurrently package: https://www.npmjs.com/package/concurrentlyTyler Flint
04/02/2021, 3:41 PMconcurrently "webpack --watch" "sst start"Tyler Flint
04/02/2021, 3:42 PMTyler Flint
04/02/2021, 3:46 PMTyler Flint
04/02/2021, 3:50 PMbuildCmd and devCmd in the sst.json, and substitute the current esbuild process for those if they exist. With this simple addition you could support anything that lambda currently supports.Tyler Flint
04/02/2021, 3:55 PMTyler Flint
04/02/2021, 3:57 PMFrank
Frank
buildCmd as Tyler suggested makes sense. Even with the Go runtime I’m working on right now I can see a usecase of overriding the default go build command.Tyler Flint
04/02/2021, 5:04 PMTyler Flint
04/02/2021, 5:04 PMgraphql: new sst.Function(this, "graphql", {
handler: 'dist/graphql.main',
environment: env,
memorySize: 256,
timeout: 30,
}),Tyler Flint
04/02/2021, 5:05 PMdist/graphql.main is a generated file. Here’s a shot of the top of the file:Frank
Tyler Flint
04/02/2021, 5:07 PMconst fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const entries = (dir) => {
return fs.readdirSync(path.resolve(__dirname, dir)).reduce((res, file) => {
// split the file at the extension
const [name, extension] = file.split('.');
// only add the entry if it's a coffeescript or javascript file
if (extension.match(/coffee|js/))
res[name] = `${path.resolve(__dirname, dir)}/${file}`;
return res;
}, {});
};
module.exports = {
entry: entries('src/lambda'),
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
libraryTarget: "umd"
},
mode: 'development',
target: 'node',
externals: ['aws-sdk', 'bufferutil', 'utf-8-validate'],
node: false,
optimization: {
usedExports: true,
},
plugins: [
new webpack.ContextReplacementPlugin(/any-promise/),
new CleanWebpackPlugin()
],
devtool: 'inline-cheap-module-source-map',
module: {
rules: [
{
test: /\.coffee$/,
loader: 'coffee-loader',
options: {
inlineMap: true,
transpile: {
presets: ['@babel/env']
}
}
}
]
},
resolve: {
alias: {
'~' : path.resolve(__dirname, 'src'),
'busboy' : path.resolve(__dirname, 'src/app/null.coffee'),
'apollo-reporting-protobuf' : path.resolve(__dirname, 'src/app/null.coffee'),
'apollo-tools' : path.resolve(__dirname, 'src/app/null.coffee'),
},
extensions: [ '.wasm', '.mjs', '.js', '.coffee', '.json' ]
}
};Tyler Flint
04/02/2021, 5:08 PMTyler Flint
04/02/2021, 5:09 PMTyler Flint
04/02/2021, 5:10 PMFrank
Tyler Flint
04/02/2021, 5:11 PMTyler Flint
04/02/2021, 5:13 PMTyler Flint
04/02/2021, 5:15 PMFrank
/dist and sst start watcher gets then triggeredTyler Flint
04/02/2021, 5:17 PMTyler Flint
04/02/2021, 5:18 PM"scripts": {
"dev": "concurrently 'webpack --watch' 'sst start'",Tyler Flint
04/02/2021, 5:18 PMFrank
Tyler Flint
04/02/2021, 5:19 PMcompile script that is just webpackTyler Flint
04/02/2021, 5:19 PMcompile first before buildTyler Flint
04/02/2021, 5:19 PMTyler Flint
04/02/2021, 5:23 PMsst start, you could support a ton of languages right off just by conditionally looking for a devCmd or similar, and if it exists run that in a pty process instead of starting the watcher/builder.Tyler Flint
04/02/2021, 5:24 PMTyler Flint
04/02/2021, 5:26 PMbuildCmd or similar could just end-run the build process and zip the contents.Tyler Flint
04/02/2021, 5:29 PM