-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Would be possible to watch only one function? #69
Comments
Replying to myself... I am now able to do the following: Assuming that:
then I can build like this: This assumes that all handlers are in const path = require("path");
const AwsSamPlugin = require("aws-sam-webpack-plugin");
module.exports = (env) => {
let awsSamPlugin = {}
const singleFunction = (env.handler && env.functionName);
if (singleFunction) {
awsSamPlugin = {
entry: () => '',
filename: () => ''
}
} else {
awsSamPlugin = new AwsSamPlugin();
}
return {
// Loads the entry object from the AWS::Serverless::Function resources in your
// SAM config. Setting this to a function will
entry: singleFunction ? './src/handlers/' + env.handler : () => awsSamPlugin.entry(),
// Write the output to the .aws-sam/build folder
output: {
filename: singleFunction ? './.aws-sam/build/' + env.functionName + '/app.js' : (chunkData) => awsSamPlugin.filename(chunkData),
libraryTarget: "commonjs2",
path: path.resolve(".")
},
// Create source maps
devtool: "source-map",
// Resolve .ts and .js extensions
resolve: {
extensions: [".ts", ".js"]
},
// Target node
target: "node",
// AWS recommends always including the aws-sdk in your Lambda package but excluding can significantly reduce
// the size of your deployment package. If you want to always include it then comment out this line. It has
// been included conditionally because the node10.x docker image used by SAM local doesn't include it.
externals: process.env.NODE_ENV === "development" ? [] : ["aws-sdk"],
// Set the webpack mode
mode: process.env.NODE_ENV || "production",
// Add the TypeScript loader
module: {
rules: [{ test: /\.tsx?$/, loader: "ts-loader" }]
},
// Add the AWS SAM Webpack plugin
plugins: singleFunction ? [] : [awsSamPlugin]
}
}; |
@graphboss I saw the source of
then it would be possible to do
thus eliminating the need to create two env variables (since If you think this is a viable change I can make a PR. |
Currently I have
npm run watch
set to runwebpack-cli -w
and mywebpack.config.js
is the same as the one shown at the beginning of the README here on Github.Currently in our SAM project my dev machine takes more than a minute to build. So I was wondering if there was a way to create a command where I can run
npm run watch myFunction
and it will only watch that single function? Usually when doing dev work I'm often only working on one single function at a time so this would be super helpful.I suspect that there is a way but my knowledge of Webpack & of the aws-sam-webpack-plugin is not great. Any ideas?
The text was updated successfully, but these errors were encountered: