在我的一个lambda函数中,我试图使用SES发送电子邮件,用于使用EJS的电子邮件,以便我可以传递一些数据并发送自定义的数据电子邮件发送给收件人。当不配置WebPack时,这是成功的。添加WebPack后,它是返回错误:enoent:无这些文件或目录。请任何人帮助我弄清楚如何解决这个问题。
我尝试在webpack.config.js文件中添加EJS文件的新规则。
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
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 no not want to minimize our code.
minimize: true,
},
performance: {
// Turn off size warnings for entry points
hints: false,
},
// Run babel on all .js files and skip those in node_modules
module: {
rules: [
{
test: /.js$/,
loader: 'babel-loader',
include: __dirname,
exclude: /node_modules/,
},
{
test: /.ejs$/,
loader: 'ejs-loader',
query: {
variable: 'data',
interpolate : '\{\{(.+?)\}\}',
evaluate : '\[\[(.+?)\]\]'
}
}
],
},
};
尝试添加此插件
plugins: [
new HtmlWebpackPlugin({
filename: "index.html",
template: "./src/index.tpl.ejs",
withAnalytics: false,
hash: true,
showErrors: true,
chunksSortMode: "dependency"
})]