drew
PPrisma
•Created by drew on 5/12/2024 in #help-and-questions
Prisma breaks lambda
webpack.config.js
const path = require('path');
const fs = require('fs');
const nodeExternals = require('webpack-node-externals');
const CopyPlugin = require('copy-webpack-plugin');
module.exports = (env) => {
return {
mode: 'production',
entry: path.resolve(__dirname, 'src', env.entry),
target: 'node',
externals: [nodeExternals()],
output: {
path: path.resolve(__dirname, 'deploy'),
filename: `${path.basename(env.entry, '.js')}.js`, // Ensure filename matches the basename of the entry file
libraryTarget: 'commonjs2'
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
},
plugins: [
new CopyPlugin({
patterns: [
{ from: 'prisma/schema.prisma', to: 'schema.prisma' }, // Ensure schema.prisma is copied to deploy directory
// You can add more patterns here if there are other static files to be included
]
})
],
optimization: {
minimize: true
},
node: {
__dirname: false,
__filename: false
}
};
};
const path = require('path');
const fs = require('fs');
const nodeExternals = require('webpack-node-externals');
const CopyPlugin = require('copy-webpack-plugin');
module.exports = (env) => {
return {
mode: 'production',
entry: path.resolve(__dirname, 'src', env.entry),
target: 'node',
externals: [nodeExternals()],
output: {
path: path.resolve(__dirname, 'deploy'),
filename: `${path.basename(env.entry, '.js')}.js`, // Ensure filename matches the basename of the entry file
libraryTarget: 'commonjs2'
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
},
plugins: [
new CopyPlugin({
patterns: [
{ from: 'prisma/schema.prisma', to: 'schema.prisma' }, // Ensure schema.prisma is copied to deploy directory
// You can add more patterns here if there are other static files to be included
]
})
],
optimization: {
minimize: true
},
node: {
__dirname: false,
__filename: false
}
};
};
9 replies
PPrisma
•Created by drew on 5/12/2024 in #help-and-questions
Prisma breaks lambda
bash
#!/bin/bash
set -vex
set -o pipefail
SRC_DIR="./src"
DEPLOY_DIR="./deploy"
rm -rf $DEPLOY_DIR
mkdir -p $DEPLOY_DIR
cp "prisma/schema.prisma" "$DEPLOY_DIR"
cp "node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node" "$DEPLOY_DIR"
for entry in $(find "$SRC_DIR" -name "*.js"); do
base_name=$(basename "$entry" .js)
echo "Bundling $entry using Webpack..."
webpack --config webpack.config.js --env entry=$base_name.js
if [ ! -f "$DEPLOY_DIR/$base_name.js" ]; then
echo "Bundled file for $base_name not found, skipping."
continue
fi
mkdir -p "$DEPLOY_DIR/tmp"
mv "$DEPLOY_DIR/$base_name.js" "$DEPLOY_DIR/tmp"
cp "$DEPLOY_DIR/schema.prisma" "$DEPLOY_DIR/tmp"
cp "$DEPLOY_DIR/libquery_engine-rhel-openssl-3.0.x.so.node" "$DEPLOY_DIR/tmp"
mkdir -p "$DEPLOY_DIR/tmp/node_modules/@prisma"
cp -r node_modules/@prisma/client "$DEPLOY_DIR/tmp/node_modules/@prisma/client"
cp -r node_modules/.prisma "$DEPLOY_DIR/tmp/node_modules/.prisma"
echo "Zipping contents for $base_name..."
(cd "$DEPLOY_DIR/tmp" && zip -r "../$base_name.zip" ./*)
rm -rf "$DEPLOY_DIR/tmp"
echo "Contents of the zip file for $base_name:"
unzip -l "$DEPLOY_DIR/$base_name.zip"
done
rm -rf deploy/*.js
rm -rf deploy/*.txt
echo "Build and packaging completed."
bash
#!/bin/bash
set -vex
set -o pipefail
SRC_DIR="./src"
DEPLOY_DIR="./deploy"
rm -rf $DEPLOY_DIR
mkdir -p $DEPLOY_DIR
cp "prisma/schema.prisma" "$DEPLOY_DIR"
cp "node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node" "$DEPLOY_DIR"
for entry in $(find "$SRC_DIR" -name "*.js"); do
base_name=$(basename "$entry" .js)
echo "Bundling $entry using Webpack..."
webpack --config webpack.config.js --env entry=$base_name.js
if [ ! -f "$DEPLOY_DIR/$base_name.js" ]; then
echo "Bundled file for $base_name not found, skipping."
continue
fi
mkdir -p "$DEPLOY_DIR/tmp"
mv "$DEPLOY_DIR/$base_name.js" "$DEPLOY_DIR/tmp"
cp "$DEPLOY_DIR/schema.prisma" "$DEPLOY_DIR/tmp"
cp "$DEPLOY_DIR/libquery_engine-rhel-openssl-3.0.x.so.node" "$DEPLOY_DIR/tmp"
mkdir -p "$DEPLOY_DIR/tmp/node_modules/@prisma"
cp -r node_modules/@prisma/client "$DEPLOY_DIR/tmp/node_modules/@prisma/client"
cp -r node_modules/.prisma "$DEPLOY_DIR/tmp/node_modules/.prisma"
echo "Zipping contents for $base_name..."
(cd "$DEPLOY_DIR/tmp" && zip -r "../$base_name.zip" ./*)
rm -rf "$DEPLOY_DIR/tmp"
echo "Contents of the zip file for $base_name:"
unzip -l "$DEPLOY_DIR/$base_name.zip"
done
rm -rf deploy/*.js
rm -rf deploy/*.txt
echo "Build and packaging completed."
9 replies
PPrisma
•Created by drew on 5/12/2024 in #help-and-questions
Prisma breaks lambda
Ok I have had nothing but troubles treeshaking this and the code above didn't work as I had hoped so here is the updated versions:
9 replies
PPrisma
•Created by drew on 5/12/2024 in #help-and-questions
Prisma breaks lambda
#!/bin/bash
set -vex
set -o pipefail
# Define the source and deploy directories
SRC_DIR="./src"
DEPLOY_DIR="./deploy"
# Clean and prepare the deploy directory
rm -rf $DEPLOY_DIR
mkdir -p $DEPLOY_DIR
# Loop through each .js file in the src directory
for entry in $SRC_DIR/*.js; do
# Get the base name of the file without the extension
base_name=$(basename $entry .js)
# Run Webpack to bundle this file
webpack --config webpack.config.js --env entry=$base_name.js
# Move to the deploy directory
cd $DEPLOY_DIR
# Create a directory for this function's deployment package
mkdir -p $base_name
mv $base_name.bundle.js $base_name/
cp ../prisma/schema.prisma $base_name/
cp ../node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node $base_name/
# Zip this function's deployment package
zip -r $base_name.zip $base_name
# Clean up the function directory
rm -rf $base_name
# Move back to the project root directory
cd ..
done
# Clean up remaining .js and .txt files in the deploy directory
find $DEPLOY_DIR -type f \( -name "*.js" -o -name "*.txt" \) -delete
echo "Build and packaging completed."
#!/bin/bash
set -vex
set -o pipefail
# Define the source and deploy directories
SRC_DIR="./src"
DEPLOY_DIR="./deploy"
# Clean and prepare the deploy directory
rm -rf $DEPLOY_DIR
mkdir -p $DEPLOY_DIR
# Loop through each .js file in the src directory
for entry in $SRC_DIR/*.js; do
# Get the base name of the file without the extension
base_name=$(basename $entry .js)
# Run Webpack to bundle this file
webpack --config webpack.config.js --env entry=$base_name.js
# Move to the deploy directory
cd $DEPLOY_DIR
# Create a directory for this function's deployment package
mkdir -p $base_name
mv $base_name.bundle.js $base_name/
cp ../prisma/schema.prisma $base_name/
cp ../node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node $base_name/
# Zip this function's deployment package
zip -r $base_name.zip $base_name
# Clean up the function directory
rm -rf $base_name
# Move back to the project root directory
cd ..
done
# Clean up remaining .js and .txt files in the deploy directory
find $DEPLOY_DIR -type f \( -name "*.js" -o -name "*.txt" \) -delete
echo "Build and packaging completed."
9 replies
PPrisma
•Created by drew on 5/12/2024 in #help-and-questions
Prisma breaks lambda
I used webpack with the following setup:
This appears to work and brought my total file size down to 7.3MB when zipped using this build script:
const path = require('path');
const fs = require('fs');
const nodeExternals = require('webpack-node-externals');
const CopyPlugin = require('copy-webpack-plugin');
module.exports = (env) => {
return {
mode: 'production',
entry: path.resolve(__dirname, 'src', env.entry),
target: 'node',
externals: [nodeExternals()],
output: {
path: path.resolve(__dirname, 'deploy'),
filename: `${env.entry.replace('.js', '')}.bundle.js`,
libraryTarget: 'commonjs2'
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
},
plugins: [
new CopyPlugin({
patterns: [
{ from: 'prisma/schema.prisma', to: 'schema.prisma' }
]
})
],
optimization: {
minimize: true
},
node: {
__dirname: false,
__filename: false
}
};
};
const path = require('path');
const fs = require('fs');
const nodeExternals = require('webpack-node-externals');
const CopyPlugin = require('copy-webpack-plugin');
module.exports = (env) => {
return {
mode: 'production',
entry: path.resolve(__dirname, 'src', env.entry),
target: 'node',
externals: [nodeExternals()],
output: {
path: path.resolve(__dirname, 'deploy'),
filename: `${env.entry.replace('.js', '')}.bundle.js`,
libraryTarget: 'commonjs2'
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
},
plugins: [
new CopyPlugin({
patterns: [
{ from: 'prisma/schema.prisma', to: 'schema.prisma' }
]
})
],
optimization: {
minimize: true
},
node: {
__dirname: false,
__filename: false
}
};
};
9 replies
PPrisma
•Created by drew on 5/12/2024 in #help-and-questions
Prisma breaks lambda
generator client {
provider = "prisma-client-js"
binaryTargets = ["rhel-openssl-3.0.x"]
}
generator client {
provider = "prisma-client-js"
binaryTargets = ["rhel-openssl-3.0.x"]
}
9 replies
PPrisma
•Created by drew on 5/12/2024 in #help-and-questions
Prisma breaks lambda
nope, that didn't help
9 replies