Skip to content

Commit 56b2361

Browse files
committed
transpile to work without ES6 loader
1 parent 22314c9 commit 56b2361

File tree

4 files changed

+57
-15
lines changed

4 files changed

+57
-15
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
dist/
3+
node_modules/

package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"name": "react-resize-aware",
33
"version": "1.0.0",
44
"description": "A resize aware component used to detect sizes changes on your components",
5-
"main": "index.js",
5+
"main": "dist/resizeAware.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"prepublish": "webpack -p && echo `gzip -c dist/ink.js | wc -c`"
88
},
99
"repository": {
1010
"type": "git",
@@ -25,5 +25,12 @@
2525
"bugs": {
2626
"url": "https://github.com/FezVrasta/react-resize-aware/issues"
2727
},
28-
"homepage": "https://github.com/FezVrasta/react-resize-aware#readme"
28+
"homepage": "https://github.com/FezVrasta/react-resize-aware#readme",
29+
"devDependencies": {
30+
"babel-core": "~5",
31+
"babel-loader": "~5",
32+
"react": "~15.0.1",
33+
"react-dom": "~15.0.1",
34+
"webpack": "~1"
35+
}
2936
}

index.js renamed to src/index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//
2-
// OnComponentResize component
2+
// react-resize-aware component
33
//
44
// Triggers a `resize` event everytime the component changes its sizes
5-
// React Component by Federico Zivolo
5+
// MIT License
6+
// Copyright 2016, Federico Zivolo
67
//
78

8-
import React, { Component } from 'react'
9-
import { findDOMNode } from 'react-dom'
9+
let React = require('react')
10+
let findDOMNode = require('react-dom').findDOMNode
1011

1112
// cross browser requestAnimationFrame
1213
const requestFrame = (function(){
@@ -47,7 +48,7 @@ function resizeListener(e) {
4748
})
4849
}
4950

50-
export default class OnComponentResize extends Component {
51+
let ResizeAware = React.createClass({
5152
render() {
5253
let rootStyle = this.props.style
5354
if (rootStyle.position === 'initial') {
@@ -75,24 +76,23 @@ export default class OnComponentResize extends Component {
7576
onLoad={ (e) => { this.objectLoad(e) } } />
7677
</div>
7778
)
78-
}
79+
},
7980

8081
componentDidMount() {
8182
// init the resizeElement
8283
this.refs.resizeElement.data = 'about:blank'
83-
}
84+
},
8485

8586
componentWillUnmount() {
8687
this.state.resizeTarget.removeEventListener('resize', this.state.resizeFn)
87-
}
88+
},
8889

8990
// function called on component resize
9091
// a `resize` event will be triggered on the component
9192
onResize(evt) {
9293
var event = new Event('resize')
93-
console.log(findDOMNode(this))
9494
findDOMNode(this).dispatchEvent(event)
95-
}
95+
},
9696

9797
// called when the object is loaded
9898
objectLoad(evt) {
@@ -102,7 +102,7 @@ export default class OnComponentResize extends Component {
102102
}, function() {
103103
this.state.resizeTarget.addEventListener('resize', this.state.resizeFn)
104104
})
105-
106105
}
106+
})
107107

108-
}
108+
module.exports = ResizeAware

webpack.config.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var Path = require('path')
2+
3+
module.exports = {
4+
entry: './src/index.js',
5+
6+
devtool: 'source-map',
7+
8+
output: {
9+
libraryTarget: 'commonjs2',
10+
path: Path.resolve(__dirname, 'dist'),
11+
filename: 'resizeAware.js'
12+
},
13+
14+
externals: {
15+
react: 'react'
16+
},
17+
18+
resolve: {
19+
extensions: ['', '.js']
20+
},
21+
22+
module: {
23+
loaders: [{
24+
exclude: /node_modules/,
25+
loader: 'babel',
26+
query: {
27+
stage: 2,
28+
loose: 'all'
29+
}
30+
}]
31+
}
32+
}

0 commit comments

Comments
 (0)