Skip to content

Commit 4eace1d

Browse files
authored
Merge pull request #296 from jurajmatus/minify-options
Configurable minification
2 parents 037b521 + 143a42e commit 4eace1d

9 files changed

Lines changed: 323 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ custom:
136136
- echo hello > test
137137
rawFileExtensions: # An array of file extensions to import using the Webpack raw-loader.
138138
- csv # Defaults to ['pem', 'txt']
139+
minifyOptions: # Options for ESBuildMinifyPlugin (https://esbuild.github.io/api/#simple-options)
140+
- keepNames: true # Disable symbol name mangling during minification
139141
experiments: # Give the ability to activate and try out experimental features of Webpack
140142
141143
```

src/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = {
2929
externals: ["knex", "sharp"],
3030
// Set default file extensions to use the raw-loader with
3131
rawFileExtensions: ["pem", "txt"],
32-
experiments: {}
32+
minifyOptions: {},
33+
experiments: {},
3334
},
3435
};

src/webpack.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const ignorePackages = config.options.ignorePackages;
4141
const rawFileExtensions = config.options.rawFileExtensions;
4242
const fixPackages = convertListToObject(config.options.fixPackages);
4343
const tsConfigPath = path.resolve(servicePath, config.options.tsConfig);
44+
const minifyOptions = config.options.minifyOptions;
4445

4546
const ENABLE_ESBUILD = config.options.esbuild;
4647
const ENABLE_STATS = config.options.stats;
@@ -299,7 +300,7 @@ function plugins() {
299300

300301
if (ENABLE_LINTING) {
301302
if (parsedTsConfig.exclude) {
302-
tsEslintConfig.ignorePatterns = parsedTsConfig.exclude
303+
tsEslintConfig.ignorePatterns = parsedTsConfig.exclude;
303304
}
304305
forkTsCheckerWebpackOptions.eslint = {
305306
files: path.join(servicePath, "**/*.ts"),
@@ -475,6 +476,7 @@ module.exports = {
475476
minimizer: [
476477
new ESBuildMinifyPlugin({
477478
target: esbuildNodeVersion,
479+
...minifyOptions,
478480
}),
479481
],
480482
},

tests/minify-options/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# package directories
2+
node_modules
3+
jspm_packages
4+
5+
# Serverless directories
6+
.serverless

tests/minify-options/handler.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function namedFunction() {
2+
return null;
3+
}
4+
5+
class NamedClass {}
6+
7+
export const hello = async () => {
8+
return {
9+
statusCode: 200,
10+
body: JSON.stringify({
11+
functionName: namedFunction.name,
12+
className: NamedClass.name,
13+
}),
14+
};
15+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { runSlsCommand, clearNpmCache, errorRegex } = require("../helpers");
2+
3+
beforeEach(async () => {
4+
await clearNpmCache(__dirname);
5+
});
6+
7+
afterAll(async () => {
8+
await clearNpmCache(__dirname);
9+
});
10+
11+
test("minify-options", async () => {
12+
const result = await runSlsCommand(__dirname);
13+
14+
expect(result).not.toMatch(errorRegex);
15+
});

tests/minify-options/package-lock.json

Lines changed: 246 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/minify-options/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "esbuild",
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+
"devDependencies": {
13+
"esbuild-loader": "^2.9.2",
14+
"reflect-metadata": "^0.1.13"
15+
},
16+
"dependencies": {}
17+
}
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+
minifyOptions:
9+
keepNames: true
10+
11+
provider:
12+
name: aws
13+
runtime: nodejs14.x
14+
15+
functions:
16+
hello:
17+
handler: handler.hello

0 commit comments

Comments
 (0)