0

我正在使用serverless体系结构开发节点应用程序。我们正在使用serverless-webpack插件来构建应用程序。这里是webpack.config.js

module.exports = {
  mode: isLocal ? 'development' : 'production',
  entry: slsw.lib.entries,
  externals: [nodeExternals()],
  devtool: 'inline-cheap-module-source-map',
  resolve: {
    extensions: ['.js', '.jsx', '.json', '.ts', '.tsx']
  },
  output: {
    libraryTarget: 'commonjs2',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js'
  },
  optimization: {
    minimize: true,
    minimizer: [new TerserPlugin()],
  },
  target: 'node',
  module: {
    rules: [{
        test: /\.ts$/,
        exclude: /node_modules/,
        loader: 'ts-loader',
        options: {
          // disable type checker - we will use it in fork plugin
          transpileOnly: true
        }
      },
      {
        test: /\.(graphql|gql)$/,
        exclude: /node_modules/,
        loader: 'graphql-tag/loader',
      }
    ]
  },
  // plugins: [new ForkTsCheckerWebpackPlugin()]
};

这是serverless.yml文件:

service: app
provider:
  name: aws
  region: ${env:AWS_REGION}
  stage: ${env:STAGE}
  logRetentionInDays: 90
  role: ${env:ROLE}
  versionFunctions: false
  runtime: nodejs12.x

package:
  individually: true

plugins:
- serverless-webpack
- serverless-offline

custom:
  webpack:
    webpackConfig: './webpack-gql.config.js'
    packager: 'npm'
    includeModules: true

functions:
  ######## GraphQl ###########
  graphql:
    role: ${env:ROLE}
    runtime: nodejs12.x
    timeout: 30
    handler: aws/lambda/common/api/graphql.graphqlHandler
 
    events:
      - http:
          path: graphql
          method: post

      - http:
          path: graphql
          method: get

当我运行sls deploy --config serverless.yml 部署应用程序时,一切正常,并且 lambda 已成功部署。唯一的问题是,在部署过程中,它正在使用package-lock.json并再次安装使用过的包:

Serverless: Package lock found - Using locked versions

Serverless: Packing external modules:  graphql-compose@^7.19.3, linewrap@^0.2.1, d64@^1.0.0, graphql-scalars@^1.2.6, graphql-tools@^6.0.12

Serverless: Packaging service...

我的问题是如何在部署期间停止重新运行 npm install ,而不是node_moudles在打包外部模块时使用现有的。任何人都可以帮我解决这个问题。?

4

0 回答 0