solc-loader
Advanced tools
Comparing version 0.0.1 to 1.0.0-rc.1
38
index.js
'use strict'; | ||
var loaderUtils = require('loader-utils'); | ||
var solc = require('solc'); | ||
@@ -6,9 +7,32 @@ | ||
this.cacheable && this.cacheable(); | ||
return "module.exports = " + JSON.stringify(source); | ||
/* | ||
console.log(source); | ||
process.exit(); | ||
return source; | ||
*/ | ||
//return solc.compile(source, 1); | ||
var config = loaderUtils.getLoaderConfig(this, 'solcLoader'); | ||
console.log(config); | ||
var optimize = 1; | ||
if (config.hasOwnProperty('optimize')) { | ||
switch (config.optimize) { | ||
case '0': | ||
optimize = '0'; | ||
break; | ||
case 'false': | ||
optimize = '0'; | ||
break; | ||
default: | ||
optimize = (config.optimize) ? '1': '0'; | ||
} | ||
} | ||
var compiled = solc.compile(source, optimize); | ||
var results = {}; | ||
for (var name in compiled.contracts) { | ||
var contract = compiled.contracts[name]; | ||
if (compiled.contracts.hasOwnProperty(name)) { | ||
results[name] = { | ||
abi: JSON.parse(contract.interface), | ||
bytecode: contract.bytecode, | ||
}; | ||
} | ||
} | ||
return 'module.exports = ' + JSON.stringify(results) + ';'; | ||
}; |
{ | ||
"name": "solc-loader", | ||
"version": "0.0.1", | ||
"version": "1.0.0-rc.1", | ||
"author": "U-Zyn Chua <chua@uzyn.com>", | ||
@@ -12,4 +12,5 @@ "description": "solc loader module for webpack (WIP)", | ||
"dependencies": { | ||
"loader-utils": "0.2.x", | ||
"solc": "^0.3.1-1" | ||
} | ||
} |
@@ -1,2 +0,83 @@ | ||
# solc-loader | ||
WIP | ||
# solc loader for webpack | ||
Compiles `.sol` with [JavaScript Solidity compiler](https://github.com/chriseth/browser-solidity) and returns JavaScript objects with Application Binary Interface (ABI) and bytecode ready to be deployed on to Ethereum. | ||
Ideally to be used with [web3-loader](https://github.com/uzyn/web3-loader) for automatic deployment and ready-to-use JavaScript instances of smart contracts. | ||
## Installation | ||
```bash | ||
npm install solc-loader --save-dev | ||
``` | ||
## Usage | ||
```js | ||
var SmartContracts = require('solc!./SmartContracts.sol'); | ||
// => returns SmartContracts array with each contract name, bytecode and abi. | ||
``` | ||
### Example webpack config | ||
At your project's `webpack.config.js`: | ||
```js | ||
module.exports = { | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.sol$/, | ||
loaders: ['solc'] | ||
] | ||
} | ||
} | ||
``` | ||
### Recommended usage with web3-loader | ||
`solc-loader` would be much sweeter if used along `web3-loader`. `web3-loader` automatically deploys new/changed contracts on to Ethereum and returns ready-to-use JavaScript instances of smart contracts. | ||
At your project's `webpack.config.js`: | ||
```js | ||
module.exports = { | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.sol$/, | ||
loaders: ['web3', 'solc'] | ||
] | ||
} | ||
} | ||
``` | ||
## Extra configuration | ||
### Optimization | ||
`solc-loader` is set to compile with optimization turned on. | ||
To turn off optimization, pass `optimize=0` via either query or loader config with the key `solcLoader`. | ||
#### Query style | ||
```js | ||
loaders: ['solc?optimize=0'] | ||
// or | ||
loader: 'solc?optimize=0' | ||
``` | ||
#### Config style | ||
```js | ||
module.exports = { | ||
solcLoader: { | ||
optimize: 0 | ||
} | ||
} | ||
``` | ||
## License | ||
MIT · [U-Zyn Chua](http://uzyn.com) ([@uzyn](http://twitter.com/uzyn)) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3314
33
84
2
+ Addedloader-utils@0.2.x
+ Addedbig.js@3.2.0(transitive)
+ Addedemojis-list@2.1.0(transitive)
+ Addedjson5@0.5.1(transitive)
+ Addedloader-utils@0.2.17(transitive)
+ Addedobject-assign@4.1.1(transitive)