serverless / serverless-plugin-typescript

Serverless plugin for zero-config Typescript support
MIT License
783 stars 222 forks source link

Webpack support? #57

Open waynerobinson opened 6 years ago

waynerobinson commented 6 years ago

I notice that to get get source maps working it suggests that Webpack is required.

Is there any instructions on using this plugin with Webpack? Is it as simple as using the https://github.com/serverless-heaven/serverless-webpack plugin?

tspecht commented 6 years ago

Any news on this? Trying to get both serverless-webpack and serverless-plugin-typescript to run right now but have no luck combining it :/

jamesdixon commented 6 years ago

Anyone have any updates on this? I keep getting the following error when deploying:

The webpack plugin could not find the configuration file at: /Users/jamesdixon/Projects/scout/platform/functions/email-service/.build/webpack.config.ts

For some reason, it doesn't seem to copy over the webpack config.

waynerobinson commented 6 years ago

I've personally moved to using serverless-webpack directly with a config based off https://github.com/serverless-heaven/serverless-webpack/tree/master/examples/typescript

jamesdixon commented 6 years ago

@waynerobinson Im using serverless-webpack as well, but no luck. Going to try that config. Question: did you convert your webpack.config file to typescript or left it as .js?

waynerobinson commented 6 years ago

I'm not sure you can convert the webpack.config file to TyepScript as Webpack is the thing that ends up calling the TypeScript compiler.

jamesdixon commented 6 years ago

@waynerobinson got it. I tried the straight-up JS version, but for some reason still getting that error...hmm

waynerobinson commented 6 years ago

I would suggest taking that exact sample, getting it to work and modifying it to suit your needs.

Ultimately, when I look at any of our production TypeScript/Webpack configs these days they're not that different from a standard Webpack/Typescript config.

The key difference is the way we define the entries into the app in a Serverless way:

Here is a more generic version of one of our small production services running in Node 8.10 on Lambda using the ts-loader package.

tsconfig.json

{
  "compilerOptions": {
    "preserveConstEnums": true,
    "strictNullChecks": true,
    "sourceMap": true,
    "experimentalDecorators": true,
    "target": "es2017",
    "module": "commonjs",
    "lib": [
      "dom",
      "es2017",
      "esnext.asynciterable"
    ]
  }
}

webpack.config.js

const path = require('path');
const slsw = require('serverless-webpack');

module.exports = {
  context: __dirname,
  entry: slsw.lib.entries,
  devtool: 'source-map-support',
  resolve: {
    extensions: [
      '.js',
      '.jsx',
      '.json',
      '.ts',
      '.tsx'
    ]
  },
  output: {
    libraryTarget: 'commonjs',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js',
  },
  target: 'node',
  module: {
    rules: [
      {
        test: /\.ts(x?)$/,
        loader: 'ts-loader',
        options: {
        }
      },
    ],
  },
};
jamesdixon commented 6 years ago

@waynerobinson much appreciated! Any idea what version of serverless-webpack and serverless-plugin-typescript you're using?

waynerobinson commented 6 years ago

We don't use the serverless-plugin-typescript anymore, only serverless-webpack with that standard Webpack config to load/convert Typescript.

And all our microservices are kept as close to the latest version of all our packages as possible (the speed at which the Node community moves these through minor and major versions is the worst part about Node in my opinion).

jamesdixon commented 6 years ago

@waynerobinson ah, gotcha! Maybe that's the problem then -- just an issue with this plugin. My TS experience is limited, so I was hoping to be able to drop this in and just have it work, but no such luck.

Appreciate your help!

suku-h commented 5 years ago

Anyone have any updates on this? I keep getting the following error when deploying:

The webpack plugin could not find the configuration file at: /Users/jamesdixon/Projects/scout/platform/functions/email-service/.build/webpack.config.ts

For some reason, it doesn't seem to copy over the webpack config.

This is caused because the plugins have to be in particular order:

plugins:
  - serverless-webpack
  - serverless-plugin-typescript
  - serverless-offline

The webpack plugin should be before the serverless-plugin-typescript