Skip to content

Simple webpack loader for .sol files and typescript support.

Notifications You must be signed in to change notification settings

A-b-i-lash/webpack-sol-loader

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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
}

About

Simple webpack loader for .sol files and typescript support.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%