gpt4 book ai didi

node.js - Webpack 仍然包含明确排除的文件夹

转载 作者:太空宇宙 更新时间:2023-11-03 23:51:13 29 4
gpt4 key购买 nike

我在 nodeJs 存储库上使用 webpack 和 serverless.com 框架来部署到 AWS Lambda 函数。由于 AWS 上的 Lambda 容器已包含 aws-sdk,因此我尝试将其从打包中排除。

构建期间的输出实际上将 aws-sdk 标识为已排除:

    [41] ./src/controller/queue.ts 2.57 KiB {3} [built]
[43] ./src/controller/auth.ts 3.76 KiB {1} [built]
+ 30 hidden modules
Serverless: Excluding external modules: aws-sdk@^2.309.0
Serverless: Package lock found - Using locked versions
Serverless: Packing external modules: @hapi/joi@^16.1.5, moment-timezone@^0.5.23, axios@^0.19.0, chrome-aws-lambda@^2.0.1, puppeteer-core@^2.0.0, uuid@^2.0.3, memorystream@^0.3.1, lambda-warmer@^1.2.1, jsonwebtoken@^8.5.1, typeorm@0.2.9, js-yaml@^3.12.0
Serverless: Packaging service...

然而,构建为上传到 Lambda 的 zip 文件仍然包含 aws-sdk,并且使包接近 60MB。我还在构建过程中观察了 .webpack 中的文件夹,并注意到 node_modules 文件夹位于依赖项文件夹和服务文件夹中,并且 aws-sdk 位于服务文件夹下。虽然我不太明白这意味着什么。

感谢任何帮助。令人沮丧的是,它公然表示要排除它,但它最终还是被压缩了。

我的 webpack.config.js 如下:

const webpack = require("webpack");
const path = require("path");
const serverlessWebpack = require("serverless-webpack");
const nodeExternals = require("webpack-node-externals");
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
entry: serverlessWebpack.lib.entries,
target: 'node',
mode: serverlessWebpack.lib.webpack.isLocal ? "development" : "production",
node: {
__dirname: true
},
devtool: 'source-map',
externals: [nodeExternals()],
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: "ts-loader"
}
],
include: [__dirname],
exclude: /node_modules/
}
]
},
resolve: {
extensions: [".ts", ".tsx", ".js"]
},
output: {
libraryTarget: "commonjs",
path: path.join(__dirname, ".webpack"),
filename: "[name].js"
},
plugins: [
new webpack.EnvironmentPlugin({
NODE_ENV: "development"
}),
new CopyWebpackPlugin([
{ from: 'ormconfig.yml' },
])
]
};

在 serverless-webpack 插件的 serverless.yml 自定义部分中,我的配置是:

webpack:
webpackConfig: webpack.config.js
includeModules:
forceExclude:
- aws-sdk
packager: 'yarn'

最佳答案

您有缩进问题吗?看到 forceExcludeincludeModules 假设在同一级别吗?

应该是这样

webpack:
webpackConfig: webpack.config.js
includeModules: true
forceExclude:
- aws-sdk
packager: 'yarn'

引用:

https://github.com/serverless-heaven/serverless-webpack

关于node.js - Webpack 仍然包含明确排除的文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59430509/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com