Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jayair committed Nov 6, 2021
2 parents edf57cc + be33d11 commit 17b8b1e
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ custom:
}
```

- Excluding modules from bundling

In some cases it might be neccessary to exclude certain modules from bundling with Webpack. This can be achieved by setting the module alias to `false`:

``` yml
custom:
bundle:
aliases:
- "module-name": false
```

The `aliases` option is explained in detail in the [Webpack documentation](https://webpack.js.org/configuration/resolve/#resolvealias).

- Usage with WebStorm

Here is some info on how to get this plugin to support running tests in WebStorm — https://github.com/AnomalyInnovations/serverless-bundle/issues/5#issuecomment-582237396
Expand Down
6 changes: 5 additions & 1 deletion src/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,11 @@ function resolvePlugins() {
function alias() {
return aliases.reduce((obj, item) => {
const [key, value] = Object.entries(item)[0];
obj[key] = path.join(servicePath, value);
if (typeof value === "string") {
obj[key] = path.join(servicePath, value);
} else {
obj[key] = value;
}
return obj;
}, {});
}
Expand Down
21 changes: 21 additions & 0 deletions tests/aliases-false/aliases-false.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { runSlsCommand, clearNpmCache } = require("../helpers");

beforeEach(async () => {
await clearNpmCache(__dirname);
});

afterAll(async () => {
await clearNpmCache(__dirname);
});

test("aliases-false", async () => {
expect.assertions(1);

const webpackErrorRegex = /"TypeError: is_sorted(.*)is not a function"/;

try {
await runSlsCommand(__dirname);
} catch (err) {
expect(err.stdout).toMatch(webpackErrorRegex);
}
});
12 changes: 12 additions & 0 deletions tests/aliases-false/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import sorted from "is-sorted";

export const hello = async (event) => {
sorted([1, 2, 3]);
return {
statusCode: 200,
body: JSON.stringify({
message: "Go Serverless v1.0! Your function executed successfully!",
input: event,
}),
};
};
15 changes: 15 additions & 0 deletions tests/aliases-false/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "aliases-false",
"version": "1.0.0",
"description": "",
"main": "handler.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"is-sorted": "^1.0.5"
}
}
17 changes: 17 additions & 0 deletions tests/aliases-false/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
service: my-service

plugins:
- "../../index"

custom:
bundle:
aliases:
- "is-sorted": false

provider:
name: aws
runtime: nodejs12.x

functions:
hello:
handler: handler.hello

0 comments on commit 17b8b1e

Please sign in to comment.