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

Commit

Permalink
fix(worker): use terser for web-worker minification
Browse files Browse the repository at this point in the history
  • Loading branch information
timmywil committed Mar 30, 2021
1 parent 6033ca2 commit 5ea98f7
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 74 deletions.
110 changes: 55 additions & 55 deletions README.md

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions WORKER_LICENSES.txt
@@ -0,0 +1,10 @@
/**
* Copyright 2021 Spokestack, Inc. All Rights Reserved.
* Licensed under the MIT license.
* https://github.com/spokestack/node-spokestack/blob/develop/MIT-License.txt
*/
/**
* tensorflow.js bundled in this web worker
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
*/
17 changes: 17 additions & 0 deletions compress.ts
@@ -0,0 +1,17 @@
import { minify } from 'terser'
const fs = require('fs')

const license = fs.readFileSync('./WORKER_LICENSES.txt', 'utf8')
const code = fs.readFileSync('./dist/spokestack-web-worker.js', 'utf8')
minify(code, {
format: {
comments: false
},
compress: {
typeofs: false
}
}).then((result) => {
const minified = result.code
console.log(minified?.length)
fs.writeFileSync('./dist/spokestack-web-worker.min.js', license + minified)
})
2 changes: 1 addition & 1 deletion examples/with-next/server/index.ts
Expand Up @@ -25,7 +25,7 @@ app.prepare().then(() => {

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

expressApp.use('/graphql', bodyParser.json(), (req, res) => {
Expand Down
28 changes: 27 additions & 1 deletion package-lock.json

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

10 changes: 4 additions & 6 deletions package.json
Expand Up @@ -10,7 +10,7 @@
"docs": "typedoc --excludePrivate --plugin typedoc-plugin-markdown --hideBreadcrumbs --out docs --readme none src/index.ts src/client.ts && node tasks/docs.js",
"format": "eslint . --fix && prettier --write \"**/*.ts\" \"**/*.js\" \"**/*.md\" \"**/*.json\"",
"lint": "concurrently --raw \"eslint .\" \"npm run prettier\" \"npm run typescript\"",
"minify:worker": "uglifyjs --compress --mangle --output dist/web-worker.min.js -- dist/web-worker.js",
"minify:worker": "ts-node --skip-project compress.ts",
"prepare": "husky install && npm run build",
"prettier": "prettier --check \"**/*.md\" \"**/*.json\"",
"release": "release-it",
Expand Down Expand Up @@ -80,11 +80,11 @@
"rollup": "^2.44.0",
"rollup-plugin-typescript2": "^0.30.0",
"sinon": "^10.0.0",
"terser": "^5.6.1",
"ts-node": "^9.1.1",
"typedoc": "^0.20.33",
"typedoc-plugin-markdown": "^3.6.0",
"typescript": "^4.2.3",
"uglify-js": "^3.13.3"
"typescript": "^4.2.3"
},
"prettier": {
"printWidth": 100,
Expand Down Expand Up @@ -139,9 +139,7 @@
"dist",
"examples",
".next",
"*.d.ts",
"tfjs.js",
"web-worker.js"
"*.d.ts"
],
"release-it": {
"hooks": {
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Expand Up @@ -84,7 +84,7 @@ const worker = {
],
output: {
format: 'iife',
file: 'dist/web-worker.js'
file: 'dist/spokestack-web-worker.js'
},
watch: {
include: ['src/worker/**']
Expand Down
2 changes: 1 addition & 1 deletion src/client/pipeline.ts
Expand Up @@ -129,7 +129,7 @@ let pipeline: SpeechPipeline | undefined
* ```ts
* app.use(
* '/spokestack-web-worker.js',
* express.static(`./node_modules/spokestack/dist/web-worker.min.js`)
* express.static(`./node_modules/spokestack/dist/spokestack-web-worker.min.js`)
* )
* ```
*
Expand Down
7 changes: 0 additions & 7 deletions src/worker/index.ts
@@ -1,10 +1,3 @@
/**
* @license
* Copyright 2021 Spokestack, Inc. All Rights Reserved.
* Licensed under the MIT license.
* https://github.com/spokestack/node-spokestack/blob/develop/MIT-License.txt
*/

import { SpeechConfig, SpeechEvent, SpeechEventType, Stage } from '../client/types'
import { SpeechContext, SpeechProcessor } from './types'

Expand Down
2 changes: 1 addition & 1 deletion src/worker/tsconfig.json
Expand Up @@ -3,6 +3,6 @@
"compilerOptions": {
"lib": ["WebWorker", "esnext"]
},
"exclude": ["node_modules"],
"exclude": ["node_modules", "compress.ts"],
"include": ["./**/*.ts"]
}
10 changes: 9 additions & 1 deletion tsconfig.json
Expand Up @@ -19,5 +19,13 @@
"strict": true,
"target": "es5"
},
"exclude": ["client.d.ts", "node_modules", "examples", "test", "dist", "src/worker"]
"exclude": [
"client.d.ts",
"compress.ts",
"node_modules",
"examples",
"test",
"dist",
"src/worker"
]
}

0 comments on commit 5ea98f7

Please sign in to comment.