webpack-sol-loader
v0.1.33
Published
Simple webpack loader for .sol files and typescript support.
Downloads
9
Maintainers
Readme
Loader for .sol files and typescript support.
Compiles .sol
with Solidity compiler.
Provides following object depending on imported .sol
file.
interface SolidityDocument {
abi: AbiItem,
bytecode: string,
contracts: undefined
}
interface SolidityDocumentCollection {
contracts: SolidityDocument[]
}
Installation
npm install webpack-sol-loader --save-dev
Usage
Update your webpack.config.ts
:
const config: Configuration = {
module: {
rules: [{
test: /\.sol?$/,
use: {
loader: 'webpack-sol-loader'
}
}]
}
}
Just import .sol file
import wallet from './wallet.sol'
// => returns SolidityDocument or SolidityDocumentCollection that are written above.
Types
Create file webpack-sol-loader.d.ts and include the following:
type AbiType = 'function' | 'constructor' | 'event' | 'fallback' | 'receive';
type StateMutabilityType = 'pure' | 'view' | 'nonpayable' | 'payable';
interface AbiInput {
name: string;
type: string;
indexed?: boolean;
components?: AbiInput[];
internalType?: string;
}
interface AbiOutput {
name: string;
type: string;
components?: AbiOutput[];
internalType?: string;
}
interface AbiItem {
anonymous?: boolean;
constant?: boolean;
inputs?: AbiInput[];
name?: string;
outputs?: AbiOutput[];
payable?: boolean;
stateMutability?: StateMutabilityType;
type: AbiType;
gas?: number;
}
interface SolidityDocument {
abi: AbiItem,
bytecode: string,
contracts: undefined
}
interface SolidityDocumentCollection {
abi: undefined,
source: undefined,
bytecode: undefined
contracts: SolidityDocument[]
}
declare module '*.sol' {
const value: SolidityDocument | SolidityDocumentCollection
export default value
}