Skip to content

Commit

Permalink
Merge pull request #296 from jurajmatus/minify-options
Browse files Browse the repository at this point in the history
Configurable minification
  • Loading branch information
jayair authored Aug 24, 2022
2 parents 037b521 + 143a42e commit 4eace1d
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ custom:
- echo hello > test
rawFileExtensions: # An array of file extensions to import using the Webpack raw-loader.
- csv # Defaults to ['pem', 'txt']
minifyOptions: # Options for ESBuildMinifyPlugin (https://esbuild.github.io/api/#simple-options)
- keepNames: true # Disable symbol name mangling during minification
experiments: # Give the ability to activate and try out experimental features of Webpack
```
Expand Down
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = {
externals: ["knex", "sharp"],
// Set default file extensions to use the raw-loader with
rawFileExtensions: ["pem", "txt"],
experiments: {}
minifyOptions: {},
experiments: {},
},
};
4 changes: 3 additions & 1 deletion src/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const ignorePackages = config.options.ignorePackages;
const rawFileExtensions = config.options.rawFileExtensions;
const fixPackages = convertListToObject(config.options.fixPackages);
const tsConfigPath = path.resolve(servicePath, config.options.tsConfig);
const minifyOptions = config.options.minifyOptions;

const ENABLE_ESBUILD = config.options.esbuild;
const ENABLE_STATS = config.options.stats;
Expand Down Expand Up @@ -299,7 +300,7 @@ function plugins() {

if (ENABLE_LINTING) {
if (parsedTsConfig.exclude) {
tsEslintConfig.ignorePatterns = parsedTsConfig.exclude
tsEslintConfig.ignorePatterns = parsedTsConfig.exclude;
}
forkTsCheckerWebpackOptions.eslint = {
files: path.join(servicePath, "**/*.ts"),
Expand Down Expand Up @@ -475,6 +476,7 @@ module.exports = {
minimizer: [
new ESBuildMinifyPlugin({
target: esbuildNodeVersion,
...minifyOptions,
}),
],
},
Expand Down
6 changes: 6 additions & 0 deletions tests/minify-options/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# package directories
node_modules
jspm_packages

# Serverless directories
.serverless
15 changes: 15 additions & 0 deletions tests/minify-options/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function namedFunction() {
return null;
}

class NamedClass {}

export const hello = async () => {
return {
statusCode: 200,
body: JSON.stringify({
functionName: namedFunction.name,
className: NamedClass.name,
}),
};
};
15 changes: 15 additions & 0 deletions tests/minify-options/minify-options.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { runSlsCommand, clearNpmCache, errorRegex } = require("../helpers");

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

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

test("minify-options", async () => {
const result = await runSlsCommand(__dirname);

expect(result).not.toMatch(errorRegex);
});
246 changes: 246 additions & 0 deletions tests/minify-options/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions tests/minify-options/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "esbuild",
"version": "1.0.0",
"description": "",
"main": "handler.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"esbuild-loader": "^2.9.2",
"reflect-metadata": "^0.1.13"
},
"dependencies": {}
}
17 changes: 17 additions & 0 deletions tests/minify-options/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
service: my-service

plugins:
- '../../index'

custom:
bundle:
minifyOptions:
keepNames: true

provider:
name: aws
runtime: nodejs14.x

functions:
hello:
handler: handler.hello

0 comments on commit 4eace1d

Please sign in to comment.