serverless-plugin-tree-shake icon indicating copy to clipboard operation
serverless-plugin-tree-shake copied to clipboard

Serveless 3 doesn't work with this plugin

Open denlight opened this issue 2 years ago • 5 comments

image

Here is a commit history https://github.com/serverless/serverless/commit/7624d8b0ca75fe84e3007f8598183c3e93c1f852

Please fix if possible

denlight avatar Jul 12 '22 22:07 denlight

Same issue here :eyes:

NickKelly1 avatar Jul 20 '22 21:07 NickKelly1

Doesn't work with serverless 2 either... this project is probably abandoned

ryanrubleycoates avatar Jul 24 '22 23:07 ryanrubleycoates

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

doteric avatar Jan 12 '23 15:01 doteric

Just found a PR that tried to solve this https://github.com/sergioramos/serverless-plugin-tree-shake/pull/423

weynhamz avatar Apr 03 '23 07:04 weynhamz

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 :)

mastrix avatar Sep 04 '23 18:09 mastrix