Skip to content
This repository was archived by the owner on May 6, 2022. It is now read-only.

Commit 5ea98f7

Browse files
committed
fix(worker): use terser for web-worker minification
1 parent 6033ca2 commit 5ea98f7

File tree

11 files changed

+126
-74
lines changed

11 files changed

+126
-74
lines changed

README.md

Lines changed: 55 additions & 55 deletions
Large diffs are not rendered by default.

WORKER_LICENSES.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright 2021 Spokestack, Inc. All Rights Reserved.
3+
* Licensed under the MIT license.
4+
* https://github.com/spokestack/node-spokestack/blob/develop/MIT-License.txt
5+
*/
6+
/**
7+
* tensorflow.js bundled in this web worker
8+
* Copyright 2020 Google LLC. All Rights Reserved.
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
*/

compress.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { minify } from 'terser'
2+
const fs = require('fs')
3+
4+
const license = fs.readFileSync('./WORKER_LICENSES.txt', 'utf8')
5+
const code = fs.readFileSync('./dist/spokestack-web-worker.js', 'utf8')
6+
minify(code, {
7+
format: {
8+
comments: false
9+
},
10+
compress: {
11+
typeofs: false
12+
}
13+
}).then((result) => {
14+
const minified = result.code
15+
console.log(minified?.length)
16+
fs.writeFileSync('./dist/spokestack-web-worker.min.js', license + minified)
17+
})

examples/with-next/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ app.prepare().then(() => {
2525

2626
expressApp.use(
2727
'/spokestack-web-worker.js',
28-
express.static(`./node_modules/spokestack/dist/web-worker${dev ? '' : '.min'}.js`)
28+
express.static(`./node_modules/spokestack/dist/spokestack-web-worker${dev ? '' : '.min'}.js`)
2929
)
3030

3131
expressApp.use('/graphql', bodyParser.json(), (req, res) => {

package-lock.json

Lines changed: 27 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"docs": "typedoc --excludePrivate --plugin typedoc-plugin-markdown --hideBreadcrumbs --out docs --readme none src/index.ts src/client.ts && node tasks/docs.js",
1111
"format": "eslint . --fix && prettier --write \"**/*.ts\" \"**/*.js\" \"**/*.md\" \"**/*.json\"",
1212
"lint": "concurrently --raw \"eslint .\" \"npm run prettier\" \"npm run typescript\"",
13-
"minify:worker": "uglifyjs --compress --mangle --output dist/web-worker.min.js -- dist/web-worker.js",
13+
"minify:worker": "ts-node --skip-project compress.ts",
1414
"prepare": "husky install && npm run build",
1515
"prettier": "prettier --check \"**/*.md\" \"**/*.json\"",
1616
"release": "release-it",
@@ -80,11 +80,11 @@
8080
"rollup": "^2.44.0",
8181
"rollup-plugin-typescript2": "^0.30.0",
8282
"sinon": "^10.0.0",
83+
"terser": "^5.6.1",
8384
"ts-node": "^9.1.1",
8485
"typedoc": "^0.20.33",
8586
"typedoc-plugin-markdown": "^3.6.0",
86-
"typescript": "^4.2.3",
87-
"uglify-js": "^3.13.3"
87+
"typescript": "^4.2.3"
8888
},
8989
"prettier": {
9090
"printWidth": 100,
@@ -139,9 +139,7 @@
139139
"dist",
140140
"examples",
141141
".next",
142-
"*.d.ts",
143-
"tfjs.js",
144-
"web-worker.js"
142+
"*.d.ts"
145143
],
146144
"release-it": {
147145
"hooks": {

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const worker = {
8484
],
8585
output: {
8686
format: 'iife',
87-
file: 'dist/web-worker.js'
87+
file: 'dist/spokestack-web-worker.js'
8888
},
8989
watch: {
9090
include: ['src/worker/**']

src/client/pipeline.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ let pipeline: SpeechPipeline | undefined
129129
* ```ts
130130
* app.use(
131131
* '/spokestack-web-worker.js',
132-
* express.static(`./node_modules/spokestack/dist/web-worker.min.js`)
132+
* express.static(`./node_modules/spokestack/dist/spokestack-web-worker.min.js`)
133133
* )
134134
* ```
135135
*

src/worker/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
/**
2-
* @license
3-
* Copyright 2021 Spokestack, Inc. All Rights Reserved.
4-
* Licensed under the MIT license.
5-
* https://github.com/spokestack/node-spokestack/blob/develop/MIT-License.txt
6-
*/
7-
81
import { SpeechConfig, SpeechEvent, SpeechEventType, Stage } from '../client/types'
92
import { SpeechContext, SpeechProcessor } from './types'
103

src/worker/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"compilerOptions": {
44
"lib": ["WebWorker", "esnext"]
55
},
6-
"exclude": ["node_modules"],
6+
"exclude": ["node_modules", "compress.ts"],
77
"include": ["./**/*.ts"]
88
}

0 commit comments

Comments
 (0)