I am new to truffle and webpack. Currently, I am writing all my code into this one app.js
file. Suppose I would like to have an external js file which is used to do some initializations.
Currently, my app.js
is something like:
// Import libraries we need. import { default as Web3} from 'web3'; import { default as contract } from 'truffle-contract' // Import our contract artifacts and turn them into usable abstractions. import user_artifacts from '../../build/contracts/User.json'; var User = contract(user_artifacts); var accounts; var g, c; window.App = { start: function() { var self = this; User.setProvider(web3.currentProvider); web3.eth.getAccounts(function(err, accs){ if (err) { alert("Error loading accounts"); return; } if (accs.length == 0) { alert("Couldn't get any accounts! Make sure your Ethereum client is configured correctly."); return; } accounts = accs; }); // Load/Initiatize these variables from an external js files g = document.getElementById("government-register"); c = document.getElementById("customer-register"); }, }; window.addEventListener('load', function() { window.web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); } App.start(); });
I want to load the variables g
& c
from an external js file and use them anywhere in app.js
. Similarly how to use functions from an external js file in app.js
.