Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

solc-loader

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

solc-loader - npm Package Compare versions

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) + ';';
};

3

package.json
{
"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))
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc