Skip to content

Commit e37c45f

Browse files
committed
feat: add support for Serverless node devDeps exclusion feature
Serverless 0.16.0 introduced a feature which excludes Node.js dev dependencies from .zip files. The feature uses package.json to find which dependencies can be excluded. serverless/serverless#3737 This commit adds the package.json to the .build folder, so that Serverless can find the package.json file.
1 parent 72e3bd7 commit e37c45f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

example/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"dependencies": {
3+
"lodash": "^4.17.4"
4+
},
5+
"devDependencies": {
36
"@types/lodash": "^4.14.63",
4-
"lodash": "^4.17.4",
57
"serverless-plugin-typescript": "^0.1.2"
68
}
79
}

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ class ServerlessPlugin {
9191
fs.symlinkSync(path.resolve('node_modules'), path.resolve(path.join(buildFolder, 'node_modules')))
9292
}
9393

94+
// include package.json into build so Serverless can exlcude devDeps during packaging
95+
if (!fs.existsSync(path.resolve(path.join(buildFolder, 'package.json')))) {
96+
fs.symlinkSync(path.resolve('package.json'), path.resolve(path.join(buildFolder, 'package.json')))
97+
}
98+
9499
// include any "extras" from the "include" section
95100
if (this.serverless.service.package.include && this.serverless.service.package.include.length > 0) {
96101
const files = await globby(this.serverless.service.package.include)

0 commit comments

Comments
 (0)