From f44c654926845231e920b4b31c92dd62bd0a75fc Mon Sep 17 00:00:00 2001 From: Adrien Cacciaguerra Date: Wed, 15 Sep 2021 16:23:01 +0200 Subject: [PATCH] Switch from serverless-webpack to serverless-esbuild --- .../aws-nodejs-typescript/package.json | 8 +-- .../aws-nodejs-typescript/serverless.ts | 13 +++-- .../aws-nodejs-typescript/webpack.config.js | 57 ------------------- 3 files changed, 11 insertions(+), 67 deletions(-) delete mode 100644 lib/plugins/create/templates/aws-nodejs-typescript/webpack.config.js diff --git a/lib/plugins/create/templates/aws-nodejs-typescript/package.json b/lib/plugins/create/templates/aws-nodejs-typescript/package.json index 04a59b673efa..d835affd8e13 100644 --- a/lib/plugins/create/templates/aws-nodejs-typescript/package.json +++ b/lib/plugins/create/templates/aws-nodejs-typescript/package.json @@ -20,14 +20,10 @@ "@types/node": "^14.14.25", "json-schema-to-ts": "^1.5.0", "serverless": "^2.23.0", - "serverless-webpack": "^5.3.5", - "ts-loader": "^8.0.15", + "serverless-esbuild": "^1.17.1", "ts-node": "^9.1.1", "tsconfig-paths": "^3.9.0", - "tsconfig-paths-webpack-plugin": "^3.3.0", - "typescript": "^4.1.3", - "webpack": "^5.20.2", - "webpack-node-externals": "^2.5.2" + "typescript": "^4.1.3" }, "author": "The serverless webpack authors (https://github.com/elastic-coders/serverless-webpack)", "license": "MIT" diff --git a/lib/plugins/create/templates/aws-nodejs-typescript/serverless.ts b/lib/plugins/create/templates/aws-nodejs-typescript/serverless.ts index 74a2a88a337d..e4114351209d 100644 --- a/lib/plugins/create/templates/aws-nodejs-typescript/serverless.ts +++ b/lib/plugins/create/templates/aws-nodejs-typescript/serverless.ts @@ -6,12 +6,17 @@ const serverlessConfiguration: AWS = { service: 'aws-nodejs-typescript', frameworkVersion: '2', custom: { - webpack: { - webpackConfig: './webpack.config.js', - includeModules: true, + esbuild: { + bundle: true, + minify: false, + sourcemap: true, + exclude: ['aws-sdk'], + target: 'node14', + define: { 'require.resolve': undefined }, + platform: 'node', }, }, - plugins: ['serverless-webpack'], + plugins: ['serverless-esbuild'], provider: { name: 'aws', runtime: 'nodejs14.x', diff --git a/lib/plugins/create/templates/aws-nodejs-typescript/webpack.config.js b/lib/plugins/create/templates/aws-nodejs-typescript/webpack.config.js deleted file mode 100644 index 0c9129252a27..000000000000 --- a/lib/plugins/create/templates/aws-nodejs-typescript/webpack.config.js +++ /dev/null @@ -1,57 +0,0 @@ -const path = require('path'); -const slsw = require('serverless-webpack'); -const nodeExternals = require('webpack-node-externals'); -const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'); - -/* -This line is only required if you are specifying `TS_NODE_PROJECT` for whatever reason. - */ -// delete process.env.TS_NODE_PROJECT; - -module.exports = { - context: __dirname, - mode: slsw.lib.webpack.isLocal ? 'development' : 'production', - entry: slsw.lib.entries, - devtool: slsw.lib.webpack.isLocal ? 'eval-cheap-module-source-map' : 'source-map', - resolve: { - extensions: ['.mjs', '.json', '.ts'], - symlinks: false, - cacheWithContext: false, - plugins: [ - new TsconfigPathsPlugin({ - configFile: './tsconfig.paths.json', - }), - ], - }, - output: { - libraryTarget: 'commonjs', - path: path.join(__dirname, '.webpack'), - filename: '[name].js', - }, - optimization: { - concatenateModules: false, - }, - target: 'node', - externals: [nodeExternals()], - module: { - rules: [ - // all files with a `.ts` or `.tsx` extension will be handled by `ts-loader` - { - test: /\.(tsx?)$/, - loader: 'ts-loader', - exclude: [ - [ - path.resolve(__dirname, 'node_modules'), - path.resolve(__dirname, '.serverless'), - path.resolve(__dirname, '.webpack'), - ], - ], - options: { - transpileOnly: true, - experimentalWatchApi: true, - }, - }, - ], - }, - plugins: [], -};