Serverless-webpack: How to include files in output zip file?

Created on 4 Apr 2018  路  4Comments  路  Source: serverless-heaven/serverless-webpack

Hi,

One of the dependencies that I use includes binary files. I want those binary files to be packed in the output zip file so the lambda functions can use them during runtime.

How can I achieve that?

I already tried to use 'file-loader' in webpack.config.js which didn't work and I tried in my serverless.yml

custom:
  webpack:
    includeModules:
      forceInclude:
        - module_name_with_binary_files

All I get are just transpiled js files of my functions.

question

Most helpful comment

hi @panzupa
Using the plugin @HyperBrain has mentioned I'm copying a file called .serverless-secrets.json (generated by https://github.com/trek10inc/serverless-secrets plugin) to my output zip file by appending the following to my webpack.config.js.

(...)
const CopyWebpackPlugin = require('copy-webpack-plugin');
(...)
plugins: [
    new CopyWebpackPlugin([
      '.serverless-secrets.json'
    ])
  ]

All 4 comments

Hi @panzupa , the file-loader is wrong for that use case as it will only include and use files that are "required" and forceInclude only is for node modules.

You can can include arbitrary files (binaries) with the webpack copy files plugin. Then webpack will copy the specified files or folders as is to the given target location within the package.

hi @panzupa
Using the plugin @HyperBrain has mentioned I'm copying a file called .serverless-secrets.json (generated by https://github.com/trek10inc/serverless-secrets plugin) to my output zip file by appending the following to my webpack.config.js.

(...)
const CopyWebpackPlugin = require('copy-webpack-plugin');
(...)
plugins: [
    new CopyWebpackPlugin([
      '.serverless-secrets.json'
    ])
  ]

Finally, I had time to check your advice.

It works flawlessly.

@HyperBrain @franciscocpg thank you very much!

I'll close this issue as it works for you 馃槃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

taschmidt picture taschmidt  路  4Comments

hassankhan picture hassankhan  路  3Comments

heri16 picture heri16  路  4Comments

rvaidya picture rvaidya  路  4Comments

tommedema picture tommedema  路  4Comments