Ignore specific Solidity files in hardhat compilation to streamline your development workflow and avoid interruptions, as fast as possiblePhoto by Mohammad Mardani on Unsplash Introduction In Solidity, the hardhat tool is often used for compilation and testing. By default, hardhat will take all .sol files in your project and compile them. However, sometimes you may only want to compile a subset of these files, and ignore others that are in development or not ready for inclusion in the compilation. This can be useful when hardhat may emit errors for files in development, which can interrupt the compilation process for deployment or testing. In this article, we'll show you how to configure hardhat to ignore specific Solidity files during compilation, so you don't have to remove or rename the files temporarily to avoid errors. Setting up hardhat.config.js 1. Importing the TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS Task The first step in configuring hardhat to ignore Solidity files is to import the TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS task from the hardhat/builtin-tasks/task-names module. This task allows you to specify a filter function that will be applied to the list of source paths before they are passed to the Solidity compiler. To import this task, add the following line to your hardhat.config.js file: import { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from "hardhat/builtin-tasks/task-names"; 2. Adding a Subtask to Filter Source Paths Once you have imported the TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS task, you can add a subtask that sets the action for this task. The action should be a function that takes three arguments: the taskArgs, taskState, and runSuper function. In the function, you can call the runSuper function to get the list of source paths that would normally be passed to the Solidity compiler. Then, you can apply a filter function to this list to remove any paths that you don't want to include in the compilation. For example, you could use a filter like this: // Add a subtask that sets the action for the TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS tasksubtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS).setAction(async (_, __, runSuper) => { // Get the list of source paths that would normally be passed to the Solidity compiler const paths = await runSuper(); // Apply a filter function to exclude paths that contain the string "ignore" return paths.filter((p: any) => !p.includes("ignore"));}); This filter will exclude any paths that contain the string “ignore” from the list of source paths passed to the Solidity compiler. You can modify this filter as needed to suit your specific requirements. With the configuration provided in this article, you can add the string “ignore” to the names of any Solidity files that you don’t want to include in the compilation. For example, if you have a file named token.ignore.sol, hardhat will not include it in the compilation process. Conclusion In this article, we showed you how to configure hardhat to ignore specific Solidity files during compilation. By importing the TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS task and adding a subtask with a custom filter function, you can control which files are included in the compilation process. This can be useful when working on large projects with many Solidity files, and can help you to focus on the files that are relevant to your current development tasks. It can also prevent hardhat from emitting errors for files in development, which can interrupt the compilation process for deployment or testing. Overall, using this method can help you to streamline your Solidity development workflow and improve the efficiency of your hardhat compilation and testing processes. `Want to Connect? You can find me on Twitter/Github/Discord` How to Ignore Solidity Files in Hardhat Compilation was originally published in Coinmonks on Medium, where people are continuing the conversation by highlighting and responding to this storyIgnore specific Solidity files in hardhat compilation to streamline your development workflow and avoid interruptions, as fast as possiblePhoto by Mohammad Mardani on Unsplash Introduction In Solidity, the hardhat tool is often used for compilation and testing. By default, hardhat will take all .sol files in your project and compile them. However, sometimes you may only want to compile a subset of these files, and ignore others that are in development or not ready for inclusion in the compilation. This can be useful when hardhat may emit errors for files in development, which can interrupt the compilation process for deployment or testing. In this article, we'll show you how to configure hardhat to ignore specific Solidity files during compilation, so you don't have to remove or rename the files temporarily to avoid errors. Setting up hardhat.config.js 1. Importing the TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS Task The first step in configuring hardhat to ignore Solidity files is to import the TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS task from the hardhat/builtin-tasks/task-names module. This task allows you to specify a filter function that will be applied to the list of source paths before they are passed to the Solidity compiler. To import this task, add the following line to your hardhat.config.js file: import { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from "hardhat/builtin-tasks/task-names"; 2. Adding a Subtask to Filter Source Paths Once you have imported the TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS task, you can add a subtask that sets the action for this task. The action should be a function that takes three arguments: the taskArgs, taskState, and runSuper function. In the function, you can call the runSuper function to get the list of source paths that would normally be passed to the Solidity compiler. Then, you can apply a filter function to this list to remove any paths that you don't want to include in the compilation. For example, you could use a filter like this: // Add a subtask that sets the action for the TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS tasksubtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS).setAction(async (_, __, runSuper) => { // Get the list of source paths that would normally be passed to the Solidity compiler const paths = await runSuper(); // Apply a filter function to exclude paths that contain the string "ignore" return paths.filter((p: any) => !p.includes("ignore"));}); This filter will exclude any paths that contain the string “ignore” from the list of source paths passed to the Solidity compiler. You can modify this filter as needed to suit your specific requirements. With the configuration provided in this article, you can add the string “ignore” to the names of any Solidity files that you don’t want to include in the compilation. For example, if you have a file named token.ignore.sol, hardhat will not include it in the compilation process. Conclusion In this article, we showed you how to configure hardhat to ignore specific Solidity files during compilation. By importing the TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS task and adding a subtask with a custom filter function, you can control which files are included in the compilation process. This can be useful when working on large projects with many Solidity files, and can help you to focus on the files that are relevant to your current development tasks. It can also prevent hardhat from emitting errors for files in development, which can interrupt the compilation process for deployment or testing. Overall, using this method can help you to streamline your Solidity development workflow and improve the efficiency of your hardhat compilation and testing processes. `Want to Connect? You can find me on Twitter/Github/Discord` How to Ignore Solidity Files in Hardhat Compilation was originally published in Coinmonks on Medium, where people are continuing the conversation by highlighting and responding to this story

How to Ignore Solidity Files in Hardhat Compilation

2025/09/09 21:43
3분 읽기
이 콘텐츠에 대한 의견이나 우려 사항이 있으시면 crypto.news@mexc.com으로 연락주시기 바랍니다

Ignore specific Solidity files in hardhat compilation to streamline your development workflow and avoid interruptions, as fast as possible

Photo by Mohammad Mardani on Unsplash

Introduction

In Solidity, the hardhat tool is often used for compilation and testing. By default, hardhat will take all .sol files in your project and compile them. However, sometimes you may only want to compile a subset of these files, and ignore others that are in development or not ready for inclusion in the compilation. This can be useful when hardhat may emit errors for files in development, which can interrupt the compilation process for deployment or testing. In this article, we'll show you how to configure hardhat to ignore specific Solidity files during compilation, so you don't have to remove or rename the files temporarily to avoid errors.

Setting up hardhat.config.js

1. Importing the TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS Task

The first step in configuring hardhat to ignore Solidity files is to import the TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS task from the hardhat/builtin-tasks/task-names module. This task allows you to specify a filter function that will be applied to the list of source paths before they are passed to the Solidity compiler.

To import this task, add the following line to your hardhat.config.js file:

import { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from "hardhat/builtin-tasks/task-names";

2. Adding a Subtask to Filter Source Paths

Once you have imported the TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS task, you can add a subtask that sets the action for this task. The action should be a function that takes three arguments: the taskArgs, taskState, and runSuper function.

In the function, you can call the runSuper function to get the list of source paths that would normally be passed to the Solidity compiler. Then, you can apply a filter function to this list to remove any paths that you don't want to include in the compilation. For example, you could use a filter like this:

// Add a subtask that sets the action for the TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS task
subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS).setAction(async (_, __, runSuper) => {
// Get the list of source paths that would normally be passed to the Solidity compiler
const paths = await runSuper();

// Apply a filter function to exclude paths that contain the string "ignore"
return paths.filter((p: any) => !p.includes("ignore"));
});

This filter will exclude any paths that contain the string “ignore” from the list of source paths passed to the Solidity compiler. You can modify this filter as needed to suit your specific requirements.

With the configuration provided in this article, you can add the string “ignore” to the names of any Solidity files that you don’t want to include in the compilation. For example, if you have a file named token.ignore.sol, hardhat will not include it in the compilation process.

Conclusion

In this article, we showed you how to configure hardhat to ignore specific Solidity files during compilation. By importing the TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS task and adding a subtask with a custom filter function, you can control which files are included in the compilation process. This can be useful when working on large projects with many Solidity files, and can help you to focus on the files that are relevant to your current development tasks. It can also prevent hardhat from emitting errors for files in development, which can interrupt the compilation process for deployment or testing. Overall, using this method can help you to streamline your Solidity development workflow and improve the efficiency of your hardhat compilation and testing processes.

`Want to Connect? You can find me on Twitter/Github/Discord`


How to Ignore Solidity Files in Hardhat Compilation was originally published in Coinmonks on Medium, where people are continuing the conversation by highlighting and responding to this story.

면책 조항: 본 사이트에 재게시된 글들은 공개 플랫폼에서 가져온 것으로 정보 제공 목적으로만 제공됩니다. 이는 반드시 MEXC의 견해를 반영하는 것은 아닙니다. 모든 권리는 원저자에게 있습니다. 제3자의 권리를 침해하는 콘텐츠가 있다고 판단될 경우, crypto.news@mexc.com으로 연락하여 삭제 요청을 해주시기 바랍니다. MEXC는 콘텐츠의 정확성, 완전성 또는 시의적절성에 대해 어떠한 보증도 하지 않으며, 제공된 정보에 기반하여 취해진 어떠한 조치에 대해서도 책임을 지지 않습니다. 본 콘텐츠는 금융, 법률 또는 기타 전문적인 조언을 구성하지 않으며, MEXC의 추천이나 보증으로 간주되어서는 안 됩니다.

USD1 Genesis: 0 Fees + 12% APR

USD1 Genesis: 0 Fees + 12% APRUSD1 Genesis: 0 Fees + 12% APR

New users: stake for up to 600% APR. Limited time!