Make parity.js usable by Node and Browser #3471
This commit is contained in:
		
							parent
							
								
									6efdc08044
								
							
						
					
					
						commit
						6fa863f2cc
					
				@ -138,6 +138,7 @@
 | 
				
			|||||||
    "mobx-react": "^3.5.8",
 | 
					    "mobx-react": "^3.5.8",
 | 
				
			||||||
    "mobx-react-devtools": "^4.2.9",
 | 
					    "mobx-react-devtools": "^4.2.9",
 | 
				
			||||||
    "moment": "^2.14.1",
 | 
					    "moment": "^2.14.1",
 | 
				
			||||||
 | 
					    "node-fetch": "^1.6.3",
 | 
				
			||||||
    "qs": "^6.3.0",
 | 
					    "qs": "^6.3.0",
 | 
				
			||||||
    "react": "^15.2.1",
 | 
					    "react": "^15.2.1",
 | 
				
			||||||
    "react-ace": "^4.0.0",
 | 
					    "react-ace": "^4.0.0",
 | 
				
			||||||
 | 
				
			|||||||
@ -14,19 +14,35 @@
 | 
				
			|||||||
// You should have received a copy of the GNU General Public License
 | 
					// You should have received a copy of the GNU General Public License
 | 
				
			||||||
// along with Parity.  If not, see <http://www.gnu.org/licenses/>.
 | 
					// along with Parity.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import 'babel-polyfill';
 | 
					import 'babel-polyfill/dist/polyfill.js';
 | 
				
			||||||
import 'whatwg-fetch';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import es6Promise from 'es6-promise';
 | 
					import es6Promise from 'es6-promise';
 | 
				
			||||||
es6Promise.polyfill();
 | 
					es6Promise.polyfill();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Api from './api';
 | 
					try {
 | 
				
			||||||
 | 
					  if (typeof self.window !== 'undefined') {
 | 
				
			||||||
 | 
					    self.window.fetch = require('isomorphic-fetch');
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					} catch (e) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					try {
 | 
				
			||||||
 | 
					  if (typeof global !== 'undefined') {
 | 
				
			||||||
 | 
					    global.fetch = require('node-fetch');
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					} catch (e) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import Api from './api';
 | 
				
			||||||
import './dev.parity.html';
 | 
					import './dev.parity.html';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// commonjs
 | 
				
			||||||
 | 
					module.exports = { Api };
 | 
				
			||||||
 | 
					// es6 default export compatibility
 | 
				
			||||||
 | 
					module.exports.default = module.exports;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if (typeof self !== 'undefined' && typeof self.window !== 'undefined') {
 | 
				
			||||||
  const api = new Api(new Api.Transport.Http('/rpc/'));
 | 
					  const api = new Api(new Api.Transport.Http('/rpc/'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
window.parity = {
 | 
					  self.window.parity = {
 | 
				
			||||||
    Api,
 | 
					    Api,
 | 
				
			||||||
    api
 | 
					    api
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -26,6 +26,7 @@ const DEST = process.env.BUILD_DEST || '.build';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
module.exports = {
 | 
					module.exports = {
 | 
				
			||||||
  context: path.join(__dirname, './src'),
 | 
					  context: path.join(__dirname, './src'),
 | 
				
			||||||
 | 
					  target: 'node',
 | 
				
			||||||
  entry: {
 | 
					  entry: {
 | 
				
			||||||
    // library
 | 
					    // library
 | 
				
			||||||
    'inject': ['./web3.js'],
 | 
					    'inject': ['./web3.js'],
 | 
				
			||||||
@ -34,7 +35,9 @@ module.exports = {
 | 
				
			|||||||
  },
 | 
					  },
 | 
				
			||||||
  output: {
 | 
					  output: {
 | 
				
			||||||
    path: path.join(__dirname, DEST),
 | 
					    path: path.join(__dirname, DEST),
 | 
				
			||||||
    filename: '[name].js'
 | 
					    filename: '[name].js',
 | 
				
			||||||
 | 
					    library: '[name].js',
 | 
				
			||||||
 | 
					    libraryTarget: 'umd'
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  module: {
 | 
					  module: {
 | 
				
			||||||
    loaders: [
 | 
					    loaders: [
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user