truffle-contract-loader

1.0.7 • Public • Published

Webpack loader for importing .sol files as Truffle contracts using truffle-compile (and by extension, its solc and Solidity version pragma).

Additionally, this loader will refrain from creating any pre-compiled contract artifact files. Dependency trees are resolved by first merging the files and then feeding the result to the compiler. Compiled contracts are stored in memory and cached.

First install the package:

yarn add truffle-contract-loader

Then insert this into your webpack config:

// webpack 2+
module.exports = {
  // ...
  module: {
    // ...
    rules: [
      // ...
      {
        test: /\.sol$/,
        use: {
          loader: 'truffle-contract-loader',
          options: {
            contracts_directory: './contracts', // required - the directory containing all your Solidity contracts
            solc: { // solc compiler options (optional) - defaults to the following (more information found here: http://solidity.readthedocs.io/en/develop/using-the-compiler.html)
              optimizer: {
                enabled: true,
                runs: 200
              }
            }
          }
        }
      }
      // ...
    ]
    // ...
  }
  // ...
}

Package Sidebar

Install

npm i truffle-contract-loader

Weekly Downloads

1

Version

1.0.7

License

ISC

Last publish

Collaborators

  • btoo