StackToolbox / aws-sam-webpack-plugin

A Webpack plugin to replace the build step for SAM CLI
MIT License
148 stars 28 forks source link

configure sam build --watch support #39

Open asankagit opened 4 years ago

asankagit commented 4 years ago

I use aws-sam-webpack-plugin with webpack to build the files.

webpack.config.js

const AwsSamPlugin = require("aws-sam-webpack-plugin");
const awsSamPlugin = new AwsSamPlugin();
const path = require('path');

module.exports = {
    //entry: './app.js',
    entry: () => awsSamPlugin.entry(),
    output: {
      path: path.resolve("."),
      filename: (chunkData) => awsSamPlugin.filename(chunkData),
      libraryTarget: 'commonjs'
    },
    target: 'node',
    mode: 'production',

      // Add the AWS SAM Webpack plugin
    plugins: [awsSamPlugin]

}

instead of using sam buld I use npm run build
in package.json

....
 "scripts": {
    "test": "mocha tests/unit/",
    "build": "webpack --watch "
  },
.....

although webpack rebuild the changes, it does not appear when sam local start-api is running, I am looking help for configure to appear changes

buggy commented 4 years ago

@asankagit Are you saying that changes to the functions aren't appearing or that changes to your SAM project aren't appearing?

asankagit commented 4 years ago

yes I have configured my webpack.config.js and package.js as above

a-mukubayashi commented 3 years ago

@asankagit Maybe you can achieve this by using two terminals.

## 1st terminal
npm run build
## 2nd terminal
sam local start-api
ryansonshine commented 3 years ago

@asankagit One solution could be to use something like concurrently like I've used on my boilerplate

The reason for the initial npm run build is to ensure the container doesn't start up with old files or an empty directory.

MarsianMan commented 3 years ago

Webpack watch does seem to work for me. The slowness makes it hard to tell if latest changes are completed or still a in progress. Sometimes I could see a build complete just as I get ready to run, but it was actually a previous build that had not finished but did not have latest changes.

I found it more efficient to manually run the build than keep wondering if I needed to wait longer for the "latest" change.