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

Publish as UMD bundle #62

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
dist
node_modules
example/*/bundle.js
*.tgz
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"name": "hyperx",
"version": "2.3.2",
"description": "tagged template string virtual dom builder",
"main": "index.js",
"main": "dist/hyperx.js",
"scripts": {
"test": "tape test/*.js",
"coverage": "covert test/*.js"
"coverage": "covert test/*.js",
"prepack": "webpack"
Copy link
Member

@goto-bus-stop goto-bus-stop Feb 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using browserify with tinyify seems simpler than placing a webpack config file in the root just for umd:

"scripts": {
  "prepublish": "browserify -s hyperx -p tinyify index.js -o dist/hyperx.js"
}

and a bit more in line with other choo-adjacent projects :)

},
"keywords": [
"jsx",
Expand All @@ -22,12 +23,15 @@
"devDependencies": {
"covert": "^1.1.0",
"hyperscript": "^1.4.7",
"hyperscript-attribute-to-property": "^1.0.0",
"tape": "^4.4.0",
"virtual-dom": "^2.1.1"
},
"dependencies": {
"hyperscript-attribute-to-property": "^1.0.0"
"uglifyjs-webpack-plugin": "^1.1.5",
"virtual-dom": "^2.1.1",
"webpack": "^3.10.0"
},
"files": [
"dist"
],
"directories": {
"example": "example",
"test": "test"
Expand Down
17 changes: 17 additions & 0 deletions readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,23 @@ var App = React.createClass({
render(React.createElement(App), document.querySelector('#content'))
```

## UMD example (via Hyperapp)

```html
<script src="https://unpkg.com/[email protected]/dist/hyperapp.js"></script>
<script src="https://unpkg.com/hyperx@latest/dist/hyperx.min.js"></script>
<script>
const {app, h} = hyperapp
const hx = hyperx(h)
const main = app(
{}, // state
{}, // actions
() => hx`<div>Hello from HyperX!</div>`,
document.getElementById('root')
)
</script>
```

## console.log example

``` js
Expand Down
19 changes: 19 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const path = require('path')

const UglifyJsPlugin = require('uglifyjs-webpack-plugin')

const cfg = minify => ({
entry: './index.js',
devtool: 'source-map',
output: {
filename: `hyperx${minify ? '.min' : ''}.js`,
library: 'hyperx',
libraryTarget: 'umd',
path: path.join(__dirname, 'dist'),
},
plugins: minify ? [new UglifyJsPlugin({
sourceMap: true,
})] : [],
})

module.exports = [cfg(false), cfg(true)]