FIXME
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
Installation
To enable this product in a buildout-based installation:
Edit your buildout.cfg and add these lines:
[buildout]
...
parts +=
node
staticresources
[node]
recipe = gp.recipe.node
version = 8.11.2
npms = npm yarn
scripts = npm yarn
[staticresources]
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.
directory
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
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.
bobtemplate
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.
- Babel
A transpiler that makes possible to use the next generation of JavaScript today.
- Sass
The most mature, stable, and powerful professional grade CSS extension language in the world.
- PostCSS
A post-processor used to transform styles with JavaScript plugins. In our configuration we use PostCSS Preset Env 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.
- HardSourceWebpackPlugin
This plugin provides an intermediate caching step for modules.
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:
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.
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
'my.package',
// shortName
'mypackage',
// path
`${__dirname}/dist`,
//publicPath
`${__dirname}/../src/my/package/browser/static`,
//callback
function(config, options) {
config.entry.unshift(
'./app/img/img1.png',
'./app/img/img2.png',
'./app/img/img3.png',
);
config.plugins.push(
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).
Usage
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).
Changelog
1.1b7 (2019-10-02)
Respect Plone external URL (closes #44). [rodfersou]
Fixes on Karma tests. [rodfersou]
1.1b5 (2018-10-05)
Replace deprecated cssnext module with PostCSS Preset Env (closes #37). [rodfersou]
Include HardSourceWebpackPlugin in default configuration; this plugin provides an intermediate caching step for modules that can speed up bundle generation up to 70% (closes #49). [rodfersou]
Fix typo on resources viewlet template. [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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file sc.recipe.staticresources-1.1b7.tar.gz
.
File metadata
- Download URL: sc.recipe.staticresources-1.1b7.tar.gz
- Upload date:
- Size: 25.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/33.1.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/2.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b46ac222ce5b74f4a99b50e667957ba1cfb46a2ebed9fbaf06a3dbe97de99234 |
|
MD5 | b1fa865323897b6c3d174035e1df3fc2 |
|
BLAKE2b-256 | 04f602601214155f0118561c40d658f3a5a3137a95c081a811da30fcd6c8ed50 |