Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support web workers #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ const { ComplexZmanimCalendar, getZmanimJson } = require("kosher-zmanim");

For UMD, a global `KosherZmanim` object is exposed.

**Web Worker**

In your worker, assuming the following project structure
```
- node_modules/
-- kosher-zmanim/
- worker.js
```
Worker code:
```javascript
importScripts('node_modules/kosher-zmanim/lib-worker/kosher-zmanim.min.js')
const { ComplexZmanimCalendar, getZmanimJson } = KosherZmanim
```

#### Library Usage:
The KosherJava library has been ported to JS, following the original API as close as possible.
The classes are exposed as named exports. You can instantiate or extend those classes as necessary, the same way you would in Java.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
"scripts": {
"clean": "rimraf ./dist/*",
"build": "npm run clean && npm run build:all && npm run webpack",
"build:all": "npm run build:cjs && npm run build:es6 && npm run build:types",
"build:all": "npm run build:cjs && npm run build:es6 && npm run build:types && npm run build:worker",
"build:cjs": "tsc -p ./src/",
"build:es6": "tsc -p ./src/tsconfig-es6.json",
"build:types": "tsc -p ./src/tsconfig-types.json",
"build:worker": "webpack --config worker.webpack.config.js",
"lint": "eslint --ext .ts src tests",
"test": "jest",
"prepublishOnly": "npm run build",
Expand Down
54 changes: 54 additions & 0 deletions worker.webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const path = require("path");
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
mode: "production",
devtool: 'source-map',
context: __dirname,
target: "webworker",
entry: {
"kosher-zmanim": "./src/kosher-zmanim.ts",
"kosher-zmanim.min": "./src/kosher-zmanim.ts",
},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "./dist/lib-worker"),
library: "KosherZmanim",
},
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: "ts-loader",
options: {
transpileOnly: true,
logInfoToStdOut: true,
compilerOptions: {
target: "es5",
module: "es6",
},
configFile: "src/tsconfig.json",
},
},
],
},
],
},
resolve: {
extensions: [".ts", ".js"],
},
optimization: {
minimizer: [new UglifyJsPlugin({
sourceMap: true,
include: /\.min\.js$/,
uglifyOptions: {
mangle: {
keep_fnames: true,
},
},
})],
},
};