Skip to content

Commit 5e04609

Browse files
committed
Added option to exclude dependencies from output package.json
1 parent 37833a0 commit 5e04609

4 files changed

Lines changed: 16 additions & 1 deletion

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ An object with the following structure:
145145
join(__dirname, "../other-workspace/package.json"),
146146
],
147147
forceWebpackVersion: "webpack5",
148+
excludeDependencies: ["aws-sdk"],
148149
}
149150
```
150151

@@ -171,6 +172,10 @@ into a final distribution project, you might want to set this option.
171172
`webpack4` or `webpack5`. If you are using a version of Webpack lower than 4- then set it to `webpack4`. This may help
172173
folks who are using Webpack in an environment where multiple versions might be present.
173174

175+
`excludeDependencies` : Here you can set any dependencies you absolutely never want in your output `package.json` file,
176+
even if they happen to be used by your code. This is useful in some edge cases, such as where an execution environment
177+
provides these dependencies for you automatically, without installation required.
178+
174179
### :mag: Things to take note of
175180

176181
You should remember to set the `"main": "./index.js"` to the correct filename (would probably be the output bundle file

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ declare class GeneratePackageJsonPlugin extends Plugin {
1313
useInstalledVersions?: boolean;
1414
resolveContextPaths?: string[];
1515
forceWebpackVersion?: "webpack4" | "webpack5";
16+
excludeDependencies?: string[];
1617
},
1718
);
1819
}

index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function GeneratePackageJsonPlugin(
2424
useInstalledVersions = true,
2525
resolveContextPaths,
2626
forceWebpackVersion,
27+
excludeDependencies = [],
2728
} = {}
2829
) {
2930
if (debug) {
@@ -62,6 +63,7 @@ function GeneratePackageJsonPlugin(
6263
useInstalledVersions,
6364
resolveContextPaths,
6465
forceWebpackVersion,
66+
excludeDependencies,
6567
});
6668
}
6769

@@ -332,6 +334,13 @@ GeneratePackageJsonPlugin.prototype.apply = function (compiler) {
332334
}
333335
}
334336

337+
for (const depName of this.excludeDependencies) {
338+
if (modules[depName] != null) {
339+
delete modules[depName];
340+
logIfDebug(`GPJWP: excluded "${depName}" from generated package.json`);
341+
}
342+
}
343+
335344
logIfDebug(`GPJWP: Modules to be used in generated package.json`, modules);
336345

337346
const finalPackageValues = Object.assign({}, basePackageValues, { dependencies: orderKeys(modules) });

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "generate-package-json-webpack-plugin",
3-
"version": "2.4.0",
3+
"version": "2.5.0",
44
"description": "Generates a package.json file containing the external modules used by your webpack bundle",
55
"main": "index.js",
66
"types": "index.d.ts",

0 commit comments

Comments
 (0)