首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >最大侦听器问题: typescript项目和无服务器的webpack

问最大侦听器问题: typescript项目和无服务器的webpack
EN

Stack Overflow用户
提问于 2021-01-16 22:55:36
回答 1查看 217关注 0票数 0

我正在做一个基于云的项目,它是用typescript构建的。来部署我们使用的服务

代码语言:javascript
复制
build : serverless webpack --stage=dev
deploy: serverless deploy --stage=dev

当在serverless.yml中定义的函数名大于10或11时,我将面临以下问题。

​

代码语言:javascript
复制
 func-abc:
    handler: src/api/get-user-details
    events:
      - http:
          authorizer: ${file(authorizer.yml)}
          path: /user/{user-id}/
          method: GET
          parameters:
            paths:
              user-id: true
          cors: true

​

webpack-config.js

代码语言:javascript
复制
const slsw = require('serverless-webpack');
const nodeExternals = require('webpack-node-externals');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
    context: __dirname,
    mode: 'production',
    entry: slsw.lib.entries,
    devtool: 'source-map',
    resolve: {
        extensions: ['.mjs', '.json', '.ts'],
        symlinks: false,
        cacheWithContext: false,
    },
    output: {
        libraryTarget: 'commonjs',
        path: path.join(__dirname, '.webpack'),
        filename: '[name].js',
    },
    target: 'node',
    optimization: {
        minimize: true,
    },
    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: [
        new ForkTsCheckerWebpackPlugin({
            eslint: true,
            eslintOptions: {
                cache: true
            }
        }),
        new CopyWebpackPlugin([
            {from: 'config/*.json', to: ''},
            {from: 'config/*.pem', to: ''},
        ])
    ],
};
代码语言:javascript
复制
(node:9972) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)

在此警告之后,代码不会部署到AWS。

如何解决这个问题。

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2021-02-17 00:32:13

它适用于我的以下webpack.config.js:

代码语言:javascript
复制
const serverlessWebpack = require('serverless-webpack');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
const TerserPlugin = require('terser-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');

module.exports = {
  devtool: 'inline-cheap-module-source-map',
  entry: serverlessWebpack.lib.entries,
  mode: 'production',
  module: {
    rules: [{
        test: /\.ts$/,
        exclude: /node_modules/,
        loader: 'ts-loader',
        options: {
          // disable type checker - we will use it in fork plugin
          transpileOnly: true
        }
      }
    ],
  },
  node: false,
  externals: [nodeExternals()],
  optimization: {
    minimize: true,
    minimizer: [new TerserPlugin({
      terserOptions: {
        keep_classnames: true,
        keep_fnames: true,
      }
    }
    )],
  },
  resolve: {
    extensions: ['.mjs', '.ts', '.js']
  },
  plugins: [
    new ForkTsCheckerWebpackPlugin()
  ],
  target: 'node',
};

最近,我正在解决类似的问题。有关详细指南( serverless+webpack),请参阅此处

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65750994

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档