Remove Theme Source Files on Deploy

Avoid exposing your theme source files on the web by removing them during your Trellis deployments.

In most scenarios, you probably don’t want someone digging into the .scss and .js files you used to build your theme. We can tell Trellis to remove the source folder for your asset builds by using the hooks in Trellis deploys.

Create a new file in trellis/deploy-hooks/build-after.yml:

- name: Remove theme source files
    state: absent
    path: "{{ deploy_helper.new_release_path }}/web/app/themes/[theme name]/resources/assets"

Add to trellis/group_vars/all/main.yml:

  - "{{ playbook_dir }}/roles/deploy/hooks/build-after.yml"
  - "{{ playbook_dir }}/deploy-hooks/build-after.yml"

Start the discussion on Roots Discourse

Help support our open-source development efforts

Help us grow

Join over 7,800+ subscribers on our newsletter to get the latest Roots updates, along with occasional tips on building better WordPress sites.

Looking for WordPress plugin recommendations, the newest modern WordPress projects, and general web development tips and articles?

“Easily the best WordPress email I get.” Colin OBrien

Follow us on Twitter @rootswp

Ready to checkout?