├── .jshintrc ├── .gitignore ├── .npmignore ├── README.md ├── package.json ├── index.js ├── LICENSE.txt └── test └── basic.js /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .DS_Store 3 | node_modules 4 | npm-debug.log 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .DS_Store 3 | /node_modules 4 | npm-debug.log 5 | /test 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-hot-transform 2 | 3 | This is an adapter for 4 | [react-hot-loader v1](https://github.com/gaearon/react-hot-loader) that is 5 | compatible with [Browserify-HMR](https://github.com/AgentME/browserify-hmr). 6 | See Browserify-HMR's Quick Example section for an example of 7 | react-hot-transform in use. 8 | 9 | **This project is unmaintained and outdated.** [React Hot Loader v3](https://github.com/gaearon/react-hot-loader) 10 | now works as a Babel plugin, so it can be used with Browserify+Babel directly and should be used instead of this. 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-hot-transform", 3 | "version": "1.0.2", 4 | "description": "React Hot Loader for Browserify. Tweak React components in real time.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/AgentME/react-hot-transform.git" 12 | }, 13 | "keywords": [ 14 | "react", 15 | "browserify", 16 | "hmr", 17 | "livereload", 18 | "live", 19 | "edit", 20 | "hot", 21 | "reload" 22 | ], 23 | "author": "Chris Cowan ", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/AgentME/react-hot-transform/issues" 27 | }, 28 | "homepage": "https://github.com/AgentME/react-hot-transform#readme", 29 | "dependencies": { 30 | "convert-source-map": "^1.1.1", 31 | "react-hot-loader": "^1.2.9", 32 | "through2": "^2.0.0" 33 | }, 34 | "devDependencies": { 35 | "mocha": "^2.3.0" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var through = require('through2'); 4 | var path = require('path'); 5 | var convert = require('convert-source-map'); 6 | var reactHotLoader = require('react-hot-loader'); 7 | 8 | module.exports = function(file, opts) { 9 | var pieces = []; 10 | return through.obj(function(row, enc, next) { 11 | pieces.push(row); 12 | next(); 13 | }, function(done) { 14 | var self = this; 15 | var source = pieces.join(''); 16 | var inputMapCV = convert.fromSource(source); 17 | var inputMap; 18 | if (inputMapCV) { 19 | inputMap = inputMapCV.toObject(); 20 | source = convert.removeComments(source); 21 | } 22 | reactHotLoader.call({ 23 | resourcePath: file, 24 | callback: function(err, source, map) { 25 | if (err) { 26 | done(err); 27 | } else { 28 | if (map) { 29 | source = source + '\n' + convert.fromJSON(map).toComment(); 30 | } 31 | self.push(source); 32 | done(); 33 | } 34 | } 35 | }, source, inputMap); 36 | }); 37 | }; 38 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Chris Cowan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /test/basic.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var ReactHotTransform = require('../index'); 3 | var convert = require('convert-source-map'); 4 | 5 | describe('react-hot-transform', function() { 6 | it('basic case works', function(done) { 7 | var stream = ReactHotTransform('/foo.js', {}); 8 | var all = []; 9 | stream.on('data', function(data) { 10 | all.push(data); 11 | }); 12 | stream.on('end', function() { 13 | var transformed = all.join(''); 14 | assert.equal(transformed.match(/REACT HOT LOADER/g).length, 2); 15 | assert.equal(transformed.match(/var x = 5;/g).length, 1); 16 | done(); 17 | }); 18 | 19 | stream.write(new Buffer("var x = 5;\n"), 'buffer'); 20 | stream.end(); 21 | }); 22 | 23 | it('multiple writes', function(done) { 24 | var stream = ReactHotTransform('/foo.js', {}); 25 | var all = []; 26 | stream.on('data', function(data) { 27 | all.push(data); 28 | }); 29 | stream.on('end', function() { 30 | var transformed = all.join(''); 31 | assert.equal(transformed.match(/REACT HOT LOADER/g).length, 2); 32 | assert.equal(transformed.match(/var x = 5;/g).length, 1); 33 | done(); 34 | }); 35 | 36 | stream.write(new Buffer("var x = "), 'buffer'); 37 | stream.write(new Buffer("5;\n"), 'buffer'); 38 | stream.end(); 39 | }); 40 | 41 | describe('sourcemaps', function() { 42 | it('no input map', function(done) { 43 | var stream = ReactHotTransform('/foo.js', {}); 44 | var all = []; 45 | stream.on('data', function(data) { 46 | all.push(data); 47 | }); 48 | stream.on('end', function() { 49 | var transformed = all.join(''); 50 | var map = convert.fromSource(transformed); 51 | assert(map); 52 | done(); 53 | }); 54 | 55 | stream.write(new Buffer("var x = 5;\n"), 'buffer'); 56 | stream.end(); 57 | }); 58 | }); 59 | }); 60 | --------------------------------------------------------------------------------