【问题标题】:How to include folder but excluding some files inside that folder when packaging for serverless?打包无服务器时如何包含文件夹但不包括该文件夹内的某些文件?
【发布时间】:2019-04-16 02:32:18
【问题描述】:

我想包含 node_modules,但排除 .bin 目录,以及 .cache 和 .yarn-integrity 文件,因为它们占用了 lambda 空间。

        exclude:
            - ./**
            - '!node_modules/**'
            - node_modules/.cache
            - node_modules/.bin
            - node_modules/.yarn-integrity

同样,我想包含“服务器”文件夹,但排除测试和 eslint 配置文件:

        exclude:
            - ./**
            - '!server/**'
            - server/**/*.test.js
            - server/.eslintrc.js

但两者都不起作用,并且文件不被排除在外。这样做的正确方法是什么?

【问题讨论】:

    标签: serverless-framework serverless aws-serverless


    【解决方案1】:

    您可以像这样在排除 node_modules/.bin 目录的同时包含 node_modules/ 目录:

    package:
       exclude:
         - node_modules/.bin/**
    

    默认情况下仅排除这些目录:

    .git/**
    .gitignore
    .DS_Store
    npm-debug.log
    .serverless/**
    .serverless_plugins/**
    

    因此,您无需指定要包含 node_modules/server/ - 它们将是默认值。只需指定要排除其中的哪些子目录。

    来源:https://serverless.com/framework/docs/providers/aws/guide/packaging/

    【讨论】:

    • 我错过了领先的 ** glob。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-14
    • 2015-08-14
    • 2016-04-29
    相关资源
    最近更新 更多