Skip to main content


Project description

Life, the Universe, and Everything

This Buildout recipe is used to integrate Plone and webpack.

In recent years, many tools were created to manage static resource files, these tools can:

  • automatically compress images
  • use CSS pre and post-processors to write less and better code, taking advantage of new standards still not available to all browsers
  • use JavaScript transpilers to write ES6 code and generate ES5 equivalent code, that works on all browsers
  • minify the resulting code

And many other options, practically everything related to process static resources can be achived by an official or community package.

This recipe let’s you write less lines into your Buildout configuration and provides a nice template to start with.

We choose webpack because it’s proven to be the best toolchain available, and many people in the Plone community are already using it.

Mostly Harmless

Got an idea? Found a bug? Let us know by opening a support ticket.

Don’t Panic


To enable this product in a buildout-based installation:

  1. Edit your buildout.cfg and add these lines:
parts +=

recipe = gp.recipe.node
version = 8.11.2
npms = npm yarn
scripts = npm yarn

recipe = sc.recipe.staticresources
name = my.package
short_name = mypackage

After updating the configuration you need to run ‘’bin/buildout’‘, which will take care of updating your system.

The recipe is responsible for:

  • creating the webpack folder structure, if none exists
  • creating the script to access webpack environment to handle more complex scenarios
  • create all scripts listed in webpack/package.json scripts entries.

Configuration options

name (required)

This is the package name or the theme name used in the package. This field is required.

short_name (required)

A short name is needed to be used as the UMD JavaScript library name and the name of the script inserted into Plone. This field is required.


Relative path to webpack folder, you can use this field to define more than one webpack folder for different themes. If this option is not present, the default value is ${buildout:directory}/webpack.


Destination path relative to webpack directory, you should add this option to point the resulting static resources folder, it can be the theme folder or a static resources directory. If this option is not present, the default value is ./dist folder.


Custom webpack bobtemplate path. It’s possible to change the default bobtemplate path to another that follows your project needs, if you prefer. If this option is not present, the default value is the bobtemplate that exists into this package.

The default template

In the default template we selected what webpack tools are valid to our needs, what is basically theme and addons development. This is the list of what we include:

HTML Loader
Used to process the HTML file; in our use case it’s used when we create a new theme.
Image Webpack Loader
Process all images referenced to save space in the final images, it tile the workflow with some specialized tools for each image format.
SVG URL Loader
Process all SVG files and creates a data-url string. For example it inserts the SVG file into the final CSS file to save requests.
Webpack SpriteSmith
Brings an easy way to create image sprites, you simply add the icon images in one folder and it creates all you need to use the sprite with your choosen CSS pre-processor.
A transpiler that makes possible to use the next generation of JavaScript today.
The most mature, stable, and powerful professional grade CSS extension language in the world.
A post-processor used to transform styles with JavaScript plugins. In our configuration we use just CSS next plugin to add automatically all vendor prefixes for the last 3 versions of major browsers, as soon as the browsers support more features, your final CSS will automatically cost less bytes.

JavaScript Helper

There’s a little helper created to simplify the configuration burden of add-ons that use this recipe. Let’s see how to use it:

  1. Create a package.json file with the following:
  "name": "my.package",
  "version": "0.0.1",
  "main": "app/mypackage.js",
  "scripts": {
    "build": "./node_modules/.bin/webpack -p",
    "debug": "NODE_ENV=debug ./node_modules/.bin/webpack --watch",
    "watch": "./node_modules/.bin/webpack -p --watch",
    "test": "NODE_ENV=testing ./node_modules/.bin/karma start --single-run"
  "repository": {},
  "license": "GPL-2.0",
  "dependencies": {
    "sc-recipe-staticresources": "simplesconsultoria/sc.recipe.staticresources#1.1b4"

This way it’s possible to add all dependencies of the configuration with just one line, keeping versions well tested across all ecosystems just like Buildout’s versions do.

  1. Create a webpack.config.js file with the following:
const makeConfig = require('sc-recipe-staticresources');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = makeConfig(
  // name

  // shortName

  // path


  function(config, options) {
      new CopyWebpackPlugin([{
        from: 'app/folder/*',
        to: 'folder',
        flatten: true


This way it’s possible to inherit a configuration of all dependencies in the current version.

Our mrbob template generates this configuration when the recipe is run for the first time. You can modify it to fit your needs, but for most themes and add-ons these defaults are a good starting point (something similar to Buildout’s extend configuration).

What is included

This recipe has included these features:

  1. Yarn This is a installation tool better than NPM because it speed up the download of packages by caching it.
  2. HardSourceWebpackPlugin This is another tool designed to speed up module build.
  3. SpritesmithPlugin This plugin is used to automatically create sprites combining the images inserted into an specific folder.
  4. Git hash Our recipe always add a hash generated by current commit revision in the end of the static files. The problem solved here is to deal with cache servers updates.


In our simplest example, the following scripts are created:

$ bin/env-mypackage

This command sets the buildout node installation in the system PATH, this way you can use webpack as described in their docs.

$ bin/watch-mypackage

This command makes webpack wait for any change in any SASS, JS (ES6) files and generates the minified version of CSS and JS (ES5) UMD module for your application.

$ bin/debug-mypackage

This does the same as watch command, but don’t try to minify the final CSS and JS. Used for debug purposes.

$ bin/build-mypackage

This command builds the CSS and JS minified, but doesn’t wait for any change.

$ bin/test-mypackage

This command runs the JavaScript tests using karma, mocha, chai and sinon.

Note that short_name is added at the end of the script name. This way you can have multiple webpack folders in the same package (if you have multiple themes inside the same package, for example).

Share and Enjoy

This package would not have been possible without the contribution of the following people:

  • Rodrigo Ferreira de Souza
  • Héctor Velarde


1.1b5 (2018-10-05)

  • Use postcss env plugin. [rodfersou]
  • Add HardSourceWebpackPlugin. [rodfersou]
  • Fix resources viewlet template generation. [rodfersou]

1.1b4 (2018-10-03)

  • Fix in javascript helper. [rodfersou]

1.1b3 (2018-10-03)

  • Fix node package version. [rodfersou]

1.1b2 (2018-10-03)

  • Use a callback to fine tune the configuration at javascript helper. [rodfersou]
  • Review to add Sprite plugin just if necessary. [rodfersou]
  • Review to add SCSS files just if necessary. [rodfersou]
  • Use script async by default. [rodfersou]
  • Fix library definition to work with Plone 5. [thet, rodfersou]
  • Emit current package version in package.json configuration (closes #40). [rodfersou]

1.1b1 (2018-09-28)

  • Create a module to reuse configuration. [rodfersou]

1.0b1 (2018-08-24)

  • Change template to use a package Known-Good-Set (KGS). [rodfersou]
  • Update package versions. [rodfersou]

1.0a2 (2018-01-24)

  • Review how HTML and CSS are processed (closes #23). [rodfersou]
  • Remove old scripts generated by this recipe after buildout run (closes #21). [rodfersou]
  • Rename script to debug instead of dev to avoid misunderstanding (closes #22). [rodfersou]
  • Fix webpack installation conflict (closes #25). [rodfersou]
  • Fix package license typo on template. [hvelarde]
  • Run build command after update recipe (closes #18). [rodfersou]
  • Add an error log if directory parameter is invalid. [rodfersou]

1.0a1 (2017-11-21)

  • Initial release.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
sc.recipe.staticresources-1.1b5.tar.gz (19.5 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page