Building examples is the same as building any other project:
Follow the setup instructions in the top-level esp-idf README.
Set IDF_PATH environment variable to point to the path to the esp-idf top-level directory.
Change into the directory of the example you'd like to build.
make menuconfig to configure the example. Most examples require a simple WiFi SSID & password via this configuration.
make to build the example.
Follow the printed instructions to flash, or run make flash.
Each example is a standalone project. The examples do not have to be inside the esp-idf directory. You can copy an example directory to anywhere on your computer in order to make a copy that you can modify and work with.
The IDF_PATH environment variable is the only thing that connects the example to the rest of the esp-idf system.
If you're looking for a more bare-bones project to start from, try