serverless-plugin-tree-shake
serverless-plugin-tree-shake copied to clipboard
Serveless 3 doesn't work with this plugin
Here is a commit history https://github.com/serverless/serverless/commit/7624d8b0ca75fe84e3007f8598183c3e93c1f852
Please fix if possible
Same issue here :eyes:
Doesn't work with serverless 2 either... this project is probably abandoned
Sadly it looks like an abandoned project.
So if for functions that do not require the serverless framework you can use my project https://github.com/doteric/funpack which uses esbuild
under the hood.
If you do need the serverless framework then you can try the following webpack.config.js
while using serverless-webpack
:
const path = require('path');
const slsw = require('serverless-webpack');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const isLocal = slsw.lib.webpack.isLocal;
module.exports = {
mode: isLocal ? 'development' : 'production',
entry: slsw.lib.entries,
devtool: 'source-map',
resolve: {
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'],
},
output: {
libraryTarget: 'commonjs2',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
},
target: 'node',
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: [
'babel-loader',
],
},
],
},
plugins: [
new ForkTsCheckerWebpackPlugin({
eslint: {
files: './src/**/*.{ts,tsx,js,jsx}',
},
}),
],
optimization: {
minimize: false,
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: (module) => {
const packageName = module.context.match(
/[\\/]node_modules[\\/](.*?)([\\/]|$)/
)[1];
return `node_modules/npm.${packageName}`;
},
},
src: {
test: /[\\/]src[\\/]/,
name: (module) => {
const path = module.identifier().split('src/')[1].split('.');
path.pop();
return `src/${path.join('')}`;
},
},
},
},
},
}
Or you could try something like this: https://github.com/serverless/serverless/discussions/11111#discussioncomment-3563002
Just found a PR that tried to solve this https://github.com/sergioramos/serverless-plugin-tree-shake/pull/423
Just found a PR that tried to solve this #423
you're right, I've just changed paths, and work like a charm, on my side, so I've patched it, will use a patch until #423 is merged :)