Skip to content

Commit be33d11

Browse files
authored
Merge pull request #266 from ohueter/feature/support-boolean-webpack-resolve-aliases
Allow boolean values (`false`) in webpack config `resolve.alias`
2 parents a3241e2 + ff8eb60 commit be33d11

File tree

6 files changed

+83
-1
lines changed

6 files changed

+83
-1
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,19 @@ custom:
188188
}
189189
```
190190

191+
- Excluding modules from bundling
192+
193+
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`:
194+
195+
``` yml
196+
custom:
197+
bundle:
198+
aliases:
199+
- "module-name": false
200+
```
201+
202+
The `aliases` option is explained in detail in the [Webpack documentation](https://webpack.js.org/configuration/resolve/#resolvealias).
203+
191204
- Usage with WebStorm
192205

193206
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

src/webpack.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,11 @@ function resolvePlugins() {
408408
function alias() {
409409
return aliases.reduce((obj, item) => {
410410
const [key, value] = Object.entries(item)[0];
411-
obj[key] = path.join(servicePath, value);
411+
if (typeof value === "string") {
412+
obj[key] = path.join(servicePath, value);
413+
} else {
414+
obj[key] = value;
415+
}
412416
return obj;
413417
}, {});
414418
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { runSlsCommand, clearNpmCache } = require("../helpers");
2+
3+
beforeEach(async () => {
4+
await clearNpmCache(__dirname);
5+
});
6+
7+
afterAll(async () => {
8+
await clearNpmCache(__dirname);
9+
});
10+
11+
test("aliases-false", async () => {
12+
expect.assertions(1);
13+
14+
const webpackErrorRegex = /"TypeError: is_sorted(.*)is not a function"/;
15+
16+
try {
17+
await runSlsCommand(__dirname);
18+
} catch (err) {
19+
expect(err.stdout).toMatch(webpackErrorRegex);
20+
}
21+
});

tests/aliases-false/handler.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import sorted from "is-sorted";
2+
3+
export const hello = async (event) => {
4+
sorted([1, 2, 3]);
5+
return {
6+
statusCode: 200,
7+
body: JSON.stringify({
8+
message: "Go Serverless v1.0! Your function executed successfully!",
9+
input: event,
10+
}),
11+
};
12+
};

tests/aliases-false/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "aliases-false",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "handler.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"is-sorted": "^1.0.5"
14+
}
15+
}

tests/aliases-false/serverless.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
service: my-service
2+
3+
plugins:
4+
- "../../index"
5+
6+
custom:
7+
bundle:
8+
aliases:
9+
- "is-sorted": false
10+
11+
provider:
12+
name: aws
13+
runtime: nodejs12.x
14+
15+
functions:
16+
hello:
17+
handler: handler.hello

0 commit comments

Comments
 (0)