Serverless + Webpack 在.serverless/<package>.zip
.
配置
serverless.yml
...
webpack:
webpackConfig: ./webpack.config.js
includeModules: true
...
webpack.config.js
const slsw = require("serverless-webpack")
const nodeExternals = require("webpack-node-externals")
// const CopyPlugin = require("copy-webpack-plugin")
module.exports = {
entry: slsw.lib.entries,
target: 'node',
// Generate sourcemaps for proper error messages
devtool: 'source-map',
// Since 'aws-sdk' is not compatible with webpack,
// we exclude all node dependencies
externals: [nodeExternals()],
mode: slsw.lib.webpack.isLocal ? "development" : "production",
optimization: {
// We do not want to minimize our code.
minimize: false
},
performance: {
// Turn off size warnings for entry points
hints: false
},
// node: false,
// devtool: 'inline-cheap-module-source-map',
// Run babel on all .js files and skip those in node_modules
module: {
rules: [
{
test: /\.js$/,
include: __dirname,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: { node: '12' },
useBuiltIns: 'usage',
corejs: 3,
},
],
],
},
},
],
},
],
},
plugins: [
// TODO
// new CopyPlugin([
// 'path/to/specific/file',
// 'recursive/directory/**',
// ]),
],
};
附加数据
- 无服务器-Webpack 版本:“无服务器-webpack”:“^5.3.5”,
- Webpack 版本:“webpack”:“4.44.2”,
- 无服务器框架版本:1.83.2
- 操作系统:MacOS
我也尝试过其他版本组合:Serverless 2.20、webpack 5.17.0、copy-webpack-plugin 7.0.0
为什么在 ZIP 中为空文件?
更新:
我刚刚尝试在具有相同结果的示例项目sls package
之一中运行ZIP 中的空文件。