assets: add support for named bundles via the settings file
This commit is contained in:
@@ -64,6 +64,19 @@ The above will produce a minified and gzipped JS file:
|
|||||||
Pelican's debug mode is propagated to Webassets to disable asset packaging
|
Pelican's debug mode is propagated to Webassets to disable asset packaging
|
||||||
and instead work with the uncompressed assets.
|
and instead work with the uncompressed assets.
|
||||||
|
|
||||||
|
If you need to create named bundles (for example, if you need to compile SASS
|
||||||
|
files before minifying with other CSS files), you can use the ``ASSET_BUNDLES``
|
||||||
|
variable in your settings file. This is an ordered sequence of 3-tuples, where
|
||||||
|
the 3-tuple is defined as ``(name, args, kwargs)``. This tuple is passed to the
|
||||||
|
`environment's register() method`_. The following will compile two SCSS files
|
||||||
|
into a named bundle, using the ``pyscss`` filter:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
ASSET_BUNDLES = (
|
||||||
|
('scss', ['colors.scss', 'main.scss'], {'filters': 'pyscss'}),
|
||||||
|
)
|
||||||
|
|
||||||
Many of Webasset's available compilers have additional configuration options
|
Many of Webasset's available compilers have additional configuration options
|
||||||
(i.e. 'Less', 'Sass', 'Stylus', 'Closure_js'). You can pass these options to
|
(i.e. 'Less', 'Sass', 'Stylus', 'Closure_js'). You can pass these options to
|
||||||
Webassets using the ``ASSET_CONFIG`` in your settings file.
|
Webassets using the ``ASSET_CONFIG`` in your settings file.
|
||||||
@@ -78,3 +91,4 @@ LessCSS's binary:
|
|||||||
|
|
||||||
.. _Webassets: https://github.com/miracle2k/webassets
|
.. _Webassets: https://github.com/miracle2k/webassets
|
||||||
.. _Webassets documentation: http://webassets.readthedocs.org/en/latest/builtin_filters.html
|
.. _Webassets documentation: http://webassets.readthedocs.org/en/latest/builtin_filters.html
|
||||||
|
.. _environment's register() method: http://webassets.readthedocs.org/en/latest/environment.html#registering-bundles
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ def create_assets_env(generator):
|
|||||||
for item in generator.settings['ASSET_CONFIG']:
|
for item in generator.settings['ASSET_CONFIG']:
|
||||||
generator.env.assets_environment.config[item[0]] = item[1]
|
generator.env.assets_environment.config[item[0]] = item[1]
|
||||||
|
|
||||||
|
if 'ASSET_BUNDLES' in generator.settings:
|
||||||
|
for name, args, kwargs in generator.settings['ASSET_BUNDLES']:
|
||||||
|
generator.env.assets_environment.register(name, *args, **kwargs)
|
||||||
|
|
||||||
if logging.getLevelName(logger.getEffectiveLevel()) == "DEBUG":
|
if logging.getLevelName(logger.getEffectiveLevel()) == "DEBUG":
|
||||||
generator.env.assets_environment.debug = True
|
generator.env.assets_environment.debug = True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user