Skip to content

Commit

Permalink
feat: Add browser build (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Jan 14, 2020
1 parent 8f2453f commit d6162ca
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 77 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ typings/
# Build folders
lib/
deno/
dist/
*.sqlite
159 changes: 83 additions & 76 deletions package-lock.json

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

21 changes: 21 additions & 0 deletions packages/hooks/build/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const path = require('path');

module.exports = {
entry: './src/index.ts',
mode: 'production',
output: {
library: 'hooks',
libraryTarget: 'umd',
globalObject: 'this',
path: path.resolve(__dirname, '..', 'dist'),
filename: 'hooks.js'
},
resolve: {
extensions: ['.ts', '.js', '.json']
},
module: {
rules: [
{ test: /\.tsx?$/, use: ['ts-loader'], exclude: /node_modules/ }
]
}
}
8 changes: 7 additions & 1 deletion packages/hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
"main": "lib/",
"types": "lib/",
"scripts": {
"build:browser": "webpack --config build/webpack.config.js",
"build:deno": "shx mkdir -p deno && node build/deno",
"compile": "shx rm -rf lib/ && tsc",
"build": "npm run compile && npm run build:deno",
"build": "npm run compile && npm run build:deno && npm run build:browser",
"prepublish": "npm run build",
"test": "mocha --opts ../../mocha.opts --recursive test/**.test.ts test/**/*.test.ts"
},
Expand All @@ -47,5 +48,10 @@
"shx": "^0.3.2",
"ts-node": "^8.5.4",
"typescript": "^3.7.4"
},
"dependencies": {
"ts-loader": "^6.2.1",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10"
}
}
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ To a function or class without having to change its original code while also kee
- [Installation](#installation)
- [Node](#node)
- [Deno](#deno)
- [Browser](#browser)
- [Quick Example](#quick-example)
- [JavaScript](#javascript)
- [TypeScript](#typescript)
Expand Down Expand Up @@ -62,6 +63,16 @@ import { hooks } from 'https://unpkg.com/@feathersjs/hooks@latest/deno/index.ts'

> __Note:__ You might want to replace `latest` with the actual version you want to use (e.g. `https://unpkg.com/@feathersjs/hooks@^0.2.0/deno/index.ts`)
## Browser

`@feathersjs/hooks` is compatible with any module loader like Webpack and can be included in the browser directly via:

```html
<script type="text/javascript" src="//unpkg.com/@feathersjs/hooks@^0.2.0/dist/hooks.js"></script>
```

Which will make a `hooks` global variable available.

# Quick Example

## JavaScript
Expand Down

0 comments on commit d6162ca

Please sign in to comment.