Squarespace Templates are powerful tools used by millions of people every day to build their websites without writing code. Since the launch of our Developer Platform, we’ve allowed customers to enter “Developer Mode” on Squarespace Templates, giving them the ability to access and change the files that constitute the template.
Endeavor and Wright represent the next generation of Squarespace template development, and they look very different from older Squarespace templates. This is because we’ve added a build step to our dev process, enabling us to modernize our templates by writing ES6, use third-party libraries like Lodash, and split out shared code into our own template modules. We’d like to share some of the thinking that went into these changes, as well as the implications for users of the Developer Platform.
A Brief History Lesson
In the past, a Squarespace Template developer would work from a singular design and write all of the markup, styles, and scripts specific to that design. These files would then be pushed to a Git repo on our server, which would handle templating, LESS compilation, and minifying/concatenating scripts.
Although our old process had certain benefits like simplicity, ease of use, and the ability to start with a clean slate for each template build, we also discovered some limitations:
Using modern technologies like ES6 was impossible without a way to transpile to vanilla ES5.
Because we didn’t use a script bundler, we couldn’t use third-party libraries like Lodash, and had to write all of our own utils.
We increasingly ran into situations where we wanted to build the same features in different templates, but we had no way to distribute and maintain code across multiple codebases.
We decided that we needed to update our process and tooling to reflect the increasingly diverse and intensive needs of our own template developers, and to keep up with the changing landscape of web development in general.
The New Process
Our new process has incorporated a number of tools, some of which may be familiar to experienced web developers, and some of which we built to be used specifically with Squarespace.
We use NPM to handle dependency management, and NPM scripts to handle the build itself rather than a task runner like Gulp or Grunt. We had a veritable cornucopia of script bundlers to choose from, but we settled on Webpack due to its versatility and widespread use.
Here’s an example of how your template may look before and after the build:
blocks/ navigation.block collections/ blog.list blog.item blog.conf scripts/ site.js blog.js styles/ site.less blog.less site.region template.conf package.json webpack.config.js
blocks/ navigation.block collections/ blog.list blog.item blog.conf scripts/ site-bundle.js styles/ site.less blog.less site.region template.conf
You may notice that the build result looks pretty much like a current Squarespace Template. This is intentional—for our new workflow, we avoided changing the way our server parses template files, so that existing developers and consumers on our platform wouldn’t be affected.
Why and How to Use It
Even if your process bears little resemblance to Squarespace Template Development, our build can still work for you. If you want to use SASS instead of LESS, you can add a compilation step during your build—our server can handle vanilla CSS. If you want to use Browserify or Rollup instead of Webpack, you can easily install those and run them in your own NPM scripts. You can even avoid NPM scripts entirely and use Grunt or Gulp instead. As long as your build result follows the structure of a Squarespace template, you can take any steps you’d like to get there.
We’ve built a number of template modules and have been using them in our newer
templates. Available under the
@squarespace scope on NPM, these modules
a plug-and-play Ajax loader for your website,
and more. Check out the full list here.
We encourage you to use these modules in your own projects! You can also install
Toolbelt in your existing project with
npm install @squarespace/toolbelt,
clone Endeavor or
Wright on GitHub, or start
with a blank slate by cloning our base template.
If you’re interested in these types of challenges and would like to join our team, we’re hiring.