Skip to content
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

serverless include/exclude is not processed #64

Closed
hereandnow opened this issue Nov 30, 2016 · 12 comments
Closed

serverless include/exclude is not processed #64

hereandnow opened this issue Nov 30, 2016 · 12 comments

Comments

@hereandnow
Copy link

as i have seen there are/were already issues where part of this problem were discussed.

does it make sense at all? in my special case i needed the package.json (and especially the name and version)-property inside AWS.

i achieved it using the existing packExternalModules-functionality and using the existing package.json-Content without all dependencies for the tmpPackageJson. see commit here

This works for my special Case (maybe it is generally i good way to do this, if you too think i can provide a pull request for this).

What would be better i think is to make the include from serverless work. If you think this would make sense, i'm willing to contribute and make a pull request for that one. just let me know in this issue!

@hereandnow
Copy link
Author

no one?

@drazafsky
Copy link

I just recently ran into this issue as well. I would certainly like to see the webpack plugin including/excluding based on the values in the serverless.yml but I don't currently have the time to develop it myself.

@thenikso
Copy link
Contributor

the exclude/include thing looks neat and we should find a way to make it easy to use it together with webpack. I still don't have a clear idea about it. The thing is, with webpack you basically shouldn't want to include/exclude anything via serverless as the whole process should be handled by the webpack bundling process.

however clearer docs/examples on this would definitely help in using this plugin. Opinions/suggestions are welcome!

@drazafsky
Copy link

At the time I ran into this issue, I was using a setup similar to https://github.com/vitaly-t/pg-promise-demo where sql queries are being stored in external files. However, the pg-promise library doesn't require/import these and so they weren't being bundled by webpack.

After having done some more digging into webpack, I manged to get the raw-loader to add the files when bundling so my use case for this is currently solved.

@RubenSandwich
Copy link

RubenSandwich commented Feb 24, 2017

@thenikso One reason to keep exclude/include and process them only after webpack has finished is for included binaries. I have a portable binary that I ship with my lambda and I've struggling to include that whole directory with webpack.

Edit: I found the webpack loader: copy-webpack-plugin which suits my use case.

Edit 2: Actually copy-webpack-plugin does not preserve permissions so I'm just running a shell script before the build with webpack-shell-plugin to copy over the binaries.

@rstims
Copy link

rstims commented Mar 21, 2017

@RubenSandwich any chance you could post your webpack config for the binary copying? TIA

EDIT: I was able to work this out.

@RubenSandwich
Copy link

RubenSandwich commented Mar 23, 2017

@rstims Sorry for the wait. I'm happy you were able to work it out. I don't have that code anymore as my team ultimately decided to move away from binaries in our lambda deployment and instead moved towards another solution because static linking all of the binaries we needed turned out to be a pain and not easily reproducible and our project requirements demand it to be easily reproducable.

But the gist of what I did was use webpack-shell-plugin to run a shell command that did two things on the onBuildStart hook:

  1. Create the .webpack directory that serverless-webpack uses as a temp directory while building
  2. Copy over the binaries into the .webpack directory

I also cleaned up the webpack-shell-plugin to be less console happy: https://github.com/CMP-Studio/webpack-shell-plugin.

@alfondotnet
Copy link

Thanks so much @RubenSandwich , I was frustrated with this. In my case just by using:

  plugins: [
    new CopyWebpackPlugin([
      {
        from: path.join(__dirname, "binary-file")
      }
    ])

Solved the issue

@HyperBrain
Copy link
Member

HyperBrain commented Jul 31, 2017

@alfonsoperez Yes. Using the CopyWebpackPlugin is the way to go to include arbitrary files into the output package.

Can I close this issue, or is there anything left, that's blocking from deployment?

@HyperBrain
Copy link
Member

3.0.0-rc.2 now also works correctly with the file-loader and I assume all other Webpack loaders and plugins too (even the elm-loader works without problems, see #191 ). So packaging and loading external files should not be a problem anymore. Webpack should be updated to a recent version though. Closing this issue.

@ro-savage
Copy link

I am a little confused how to do this on a per function basis

if I have

/folder1/function1.js
/folder1/somebinary.jpg
/folder2/function2.js

If I do
plugins: [ new CopyWebpackPlugin([{from: 'folder1/somebinary.png'}])]

Then it will copy the file into every Lambda.

How can you make it work, so it'll only copy the file to the relavent lambda?

@sepehr
Copy link

sepehr commented Mar 12, 2018

That would be great if we could have a mechanism in place to respect serverless include/exclude configs, whether service-wide or function-wide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants