truffle-solidity-loader
A Webpack loader that allows importing a solidity contract directly. Importing returns a truffle artifact json object. This allows smart contract development with Hot Reloading support and enables migrations to automatically re-run on change. When running a production build, contracts will be bundled into main bundle for easy deployment.
Example
const Web3 = ; // currently compatible up to web3@1.0.0-beta.37const provider = "http://localhost:8545";const contract = ; ;const MyContract = ; MyContract;
You can see this plugin in operation in the Truffle+Webpack Demo App. The demo is for Truffle 4.0 & Webpack 4.
This package will re-run migration scripts whenever solidity files are modified. If you have multiple solidity files, the entire project will be redeployed.
Installation
$ npm install --save-dev truffle-solidity-loader
Add the appropriate config to your loaders
section of your Webpack 4 config:
test: /\.sol/ use: loader: 'json-loader' loader: 'truffle-solidity-loader' options: network: 'ganache'
Webpack applies loaders right to left, therefore the output of truffle-solidity-loader
goes into json-loader
.
truffle-config.js
integration
The loader will auto detect a truffle-config.js
(or truffle.js
) config file in your project and use that for configuration.
Loader options
migrations_directory
: The path truffle migration scriptsnetwork
: A network name to usecontracts_build_directory
: path to directory of truffle JSON artifacts
test: /\.sol/ use: loader: 'json-loader' loader: 'truffle-solidity-loader' options: network: 'ganache' migrations_directory: path contracts_build_directory: path
Contributing
- Open an issue to report bugs or provide feedback.
- Submit PRs.
- Respect the project coding style: StandardJS.
License
MIT