Make parity.js usable by Node and Browser #3471

This commit is contained in:
Nicolas Gotchac 2016-11-16 16:50:12 +01:00
parent 6efdc08044
commit 6fa863f2cc
3 changed files with 30 additions and 10 deletions

View File

@ -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",

View File

@ -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';
const api = new Api(new Api.Transport.Http('/rpc/')); // commonjs
module.exports = { Api };
// es6 default export compatibility
module.exports.default = module.exports;
window.parity = { if (typeof self !== 'undefined' && typeof self.window !== 'undefined') {
Api, const api = new Api(new Api.Transport.Http('/rpc/'));
api
}; self.window.parity = {
Api,
api
};
}

View File

@ -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: [